#d2113. 可重排列
可重排列
Multiset Permutations
Problem Description
Output all sequences in lexicographically increasing order such that the sequence contains copies of , copies of , , copies of .
Input Format
The first line contains an integer .
The second line contains integers .
Output Format
Output all valid sequences in lexicographically increasing order, one sequence per line. Numbers in a sequence are separated by spaces.
Sample Input
3
1 2 2
Sample Output
1 2 2 3 3
1 2 3 2 3
1 2 3 3 2
1 3 2 2 3
1 3 2 3 2
1 3 3 2 2
2 1 2 3 3
2 1 3 2 3
2 1 3 3 2
2 2 1 3 3
2 2 3 1 3
2 2 3 3 1
2 3 1 2 3
2 3 1 3 2
2 3 2 1 3
2 3 2 3 1
2 3 3 1 2
2 3 3 2 1
3 1 2 2 3
3 1 2 3 2
3 1 3 2 2
3 2 1 2 3
3 2 1 3 2
3 2 2 1 3
3 2 2 3 1
3 2 3 1 2
3 2 3 2 1
3 3 1 2 2
3 3 2 1 2
3 3 2 2 1
Constraints
For of the data, , , and the total number of valid sequences does not exceed .