#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:
- Push a character onto the left end.
- Push a character onto the right end.
- Pop the leftmost character.

You are given 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 , the length of the input.
The second line contains a string of length .
Output Format
The first line contains an integer , the number of possible dequeue orders.
The following 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, .