1031: Previous Permutation
Memory Limit:1024 MB
Time Limit:2.000 S
Judge Style:Text Compare
Creator:
Submit:15
Solved:10
Description
You are given a permutation of , where .
Assume that is the -th lexicographically smallest among all permutations of . Find the -th lexicographically smallest permutation.
Input
The input is given from Standard Input in the following format:
Output
Let be the sought permutation. Print in a single line in this order, separated by spaces.
Sample Input Copy
3
3 1 2
Sample Output Copy
2 3 1
HINT
Here are the permutations of in ascending lexicographical order.
Therefore, is the fifth smallest, so the sought permutation, which is the fourth smallest , is .