#arc160a. [arc160_a]Reverse and Count
[arc160_a]Reverse and Count
Problem Statement
You are given a permutation of .
For a pair of integers such that , let be the permutation obtained by reversing the -th through -th elements of , that is, replacing with simultaneously.
There are ways to choose such that .
If the permutations for all such pairs are listed and sorted in lexicographical order, what is the -th permutation from the front?
What is lexicographical order on sequences?
A sequence is said to be lexicographically smaller than a sequence if and only if 1. or 2. below holds. Here, and denote the lengths of and , respectively.
- and $(S_1,S_2,\\ldots,S_{|S|}) = (T_1,T_2,\\ldots,T_{|S|})$.
- There is an integer that satisfies both of the following.
- $(S_1,S_2,\\ldots,S_{i-1}) = (T_1,T_2,\\ldots,T_{i-1})$.
- is smaller than (as a number).
Constraints
- is a permutation of .
Input
The input is given from Standard Input in the following format:
Output
Let be the -th permutation from the front in the list of the permutations sorted in lexicographical order.
Print in the following format:
Sample Input 1
3 5
1 3 2
Sample Output 1
2 3 1
Here are the permutations for all pairs such that .
When these are sorted in lexicographical order, the fifth permutation is , which should be printed.
Sample Input 2
5 15
1 2 3 4 5
Sample Output 2
5 4 3 2 1
The answer is .
Sample Input 3
10 37
9 2 1 3 8 7 10 4 5 6
Sample Output 3
9 2 1 6 5 4 10 7 8 3