A permutation of length $$$n$$$ is a sequence of $$$n$$$ integers in which every integer from $$$1$$$ to $$$n$$$ appears exactly once. For a permutation $$$p_1, p_2, \ldots, p_n$$$ of length $$$n$$$, let $$$q_i$$$ denote the position where $$$i$$$ appears, i.e., $$$p_{q_i} = i$$$. If for every $$$i = 2, 3, \ldots, n-1$$$ we have $$$(q_i - q_{i-1})(q_i - q_{i+1}) \gt 0$$$, then the permutation $$$p_1, p_2, \ldots, p_n$$$ is called a turning permutation.
Now given $$$n$$$ and $$$k$$$, you need to find the $$$k$$$-th lexicographically smallest turning permutation of length $$$n$$$, or report that the number of turning permutations of length $$$n$$$ is less than $$$k$$$.
To determine which of the two permutations of length $$$n$$$ is lexicographically smaller, we compare their first elements. If they are equal, we compare the second, and so on. If we have two different permutations $$$x$$$ and $$$y$$$ of length $$$n$$$, then $$$x$$$ is lexicographically smaller if $$$x_i \lt y_i$$$, where $$$i$$$ is the first index at which the permutations $$$x$$$ and $$$y$$$ differ.
The only line contains two integers $$$n$$$ ($$$3\le n \le 50$$$) and $$$k$$$ ($$$1\le k \le 10^{18}$$$), denoting the length of the permutation and the ranking position of the desired turning permutation in the lexicographically sorted list of all the turning permutations of length $$$n$$$, respectively.
If the number of turning permutations of length $$$n$$$ is less than $$$k$$$, output $$$-1$$$ in one line. Otherwise, output the $$$k$$$-th lexicographically smallest turning permutation of length $$$n$$$ in one line.
3 2
2 1 3
3 5
-1
4 6
3 1 2 4
4 11
-1
There are a total of $$$4$$$ turning permutations of length $$$3$$$, arranged in lexicographically ascending order: $$$[1,3,2]$$$, $$$[2,1,3]$$$, $$$[2,3,1]$$$, $$$[3,1,2]$$$. Therefore, for the first sample case, the $$$2$$$nd lexicographically smallest turning permutation is $$$[2,1,3]$$$, and for the second sample case, the answer is $$$-1$$$.
There are a total of $$$10$$$ turning permutations of length $$$4$$$, arranged in lexicographically ascending order: $$$[1,3,2,4]$$$, $$$[1,3,4,2]$$$, $$$[2,1,4,3]$$$, $$$[2,4,1,3]$$$, $$$[2,4,3,1]$$$, $$$[3,1,2,4]$$$, $$$[3,1,4,2]$$$, $$$[3,4,1,2]$$$, $$$[4,2,1,3]$$$, $$$[4,2,3,1]$$$. Therefore, for the third sample case, the $$$6$$$th lexicographically smallest turning permutation is $$$[3,1,2,4]$$$, and for the fourth sample case, the answer is $$$-1$$$.
| Название |
|---|


