#d2929. 模拟输出受限制的双端队列

模拟输出受限制的双端队列

Output-Restricted Double-Ended Queue Simulation

Problem Description

You are given an output-restricted double-ended queue. "Output-restricted" means: at one end you may both push and pop an element, but at the other end you may only push and cannot pop. In each step you may perform exactly one of the following three operations:

  1. Push a character onto the left end.
  2. Push a character onto the right end.
  3. Pop the leftmost character.

deque illustration

You are given nn characters as the input of the queue. How many possible dequeue orders are there? Print all of them in lexicographic order.

Input Format

The first line contains an integer nn, the length of the input.

The second line contains a string of length nn.

Output Format

The first line contains an integer kk, the number of possible dequeue orders.

The following kk lines output each possible dequeue order in lexicographic order.

Sample Input

3
123

Sample Output

6
123
132
213
231
312
321

Constraints

For all test data, 1≤n≤71 \le n \le 7.