#arc160a. [arc160_a]Reverse and Count

[arc160_a]Reverse and Count

Problem Statement

You are given a permutation A=(A1,A2,dots,AN)A = (A_1, A_2, \\dots, A_N) of (1,2,dots,N)(1, 2, \\dots, N).
For a pair of integers (L,R)(L, R) such that 1leqLleqRleqN1 \\leq L \\leq R \\leq N, let f(L,R)f(L, R) be the permutation obtained by reversing the LL-th through RR-th elements of AA, that is, replacing AL,AL+1,dots,AR1,ARA_L, A_{L+1}, \\dots, A_{R-1}, A_R with AR,AR1,dots,AL+1,ALA_R, A_{R-1}, \\dots, A_{L+1}, A_{L} simultaneously.

There are fracN(N+1)2\\frac{N(N + 1)}{2} ways to choose (L,R)(L, R) such that 1leqLleqRleqN1 \\leq L \\leq R \\leq N.
If the permutations f(L,R)f(L, R) for all such pairs (L,R)(L, R) are listed and sorted in lexicographical order, what is the KK-th permutation from the front?

What is lexicographical order on sequences?

A sequence S=(S1,S2,ldots,SS)S = (S_1,S_2,\\ldots,S_{|S|}) is said to be lexicographically smaller than a sequence T=(T1,T2,ldots,TT)T = (T_1,T_2,\\ldots,T_{|T|}) if and only if 1. or 2. below holds. Here, S|S| and T|T| denote the lengths of SS and TT, respectively.

  1. SltT|S| \\lt |T| and $(S_1,S_2,\\ldots,S_{|S|}) = (T_1,T_2,\\ldots,T_{|S|})$.
  2. There is an integer 1leqileqminlbraceS,Trbrace1 \\leq i \\leq \\min\\lbrace |S|, |T| \\rbrace that satisfies both of the following.
    • $(S_1,S_2,\\ldots,S_{i-1}) = (T_1,T_2,\\ldots,T_{i-1})$.
    • SiS_i is smaller than TiT_i (as a number).

Constraints

  • 1leqNleq70001 \\leq N \\leq 7000
  • 1leqKleqfracN(N+1)21 \\leq K \\leq \\frac{N(N + 1)}{2}
  • AA is a permutation of (1,2,dots,N)(1, 2, \\dots, N).

Input

The input is given from Standard Input in the following format:

NN KK A1A_1 A2A_2 dots\\dots ANA_N

Output

Let B=(B1,B2,dots,BN)B =(B_1, B_2, \\dots, B_N) be the KK-th permutation from the front in the list of the permutations f(L,R)f(L, R) sorted in lexicographical order.
Print BB in the following format:

B1B_1 B2B_2 dots\\dots BNB_N


Sample Input 1

3 5
1 3 2

Sample Output 1

2 3 1

Here are the permutations f(L,R)f(L, R) for all pairs (L,R)(L, R) such that 1leqLleqRleqN1 \\leq L \\leq R \\leq N.

  • f(1,1)=(1,3,2)f(1, 1) = (1, 3, 2)
  • f(1,2)=(3,1,2)f(1, 2) = (3, 1, 2)
  • f(1,3)=(2,3,1)f(1, 3) = (2, 3, 1)
  • f(2,2)=(1,3,2)f(2, 2) = (1, 3, 2)
  • f(2,3)=(1,2,3)f(2, 3) = (1, 2, 3)
  • f(3,3)=(1,3,2)f(3, 3) = (1, 3, 2)

When these are sorted in lexicographical order, the fifth permutation is f(1,3)=(2,3,1)f(1, 3) = (2, 3, 1), 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 f(1,5)f(1, 5).


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