Chicken Top N

Print the row after one bottom-up merge sort stage by merging each pair of sorted groups of length N/(2k) into one sorted group of length N/k.

Easy3SimulationSortingInterviewNo attempts yetTime limit5sMemory limit256 MB

Problem

Minho leads C.T.P (Chicken Tastes Perfect), a club that scores the taste of the chicken shops around campus. He wants the shops lined up so the scores never decrease from left to right. There are too many shops to do it alone, so he puts the club members to work.

Suppose there are NN shops and their scores are laid out in a row in arbitrary order. In the first stage, N/2N/2 members take two shops each, going from left to right, and each member sorts the two shops. In the next stage, N/4N/4 members take two of the sorted groups each, again from left to right, and merge each pair into one sorted group. The work continues with N/8N/8 members, then N/16N/16 members, and finishes when the last member merges the two remaining sorted groups.

Take 8 shops with scores 1, 5, 2, 4, 2, 9, 7, 3. Four members sort (1, 5), (2, 4), (2, 9), (7, 3), which turns the row into (1, 5), (2, 4), (2, 9), (3, 7). Two members then merge ((1, 5), (2, 4)) and ((2, 9), (3, 7)) into (1, 2, 4, 5), (2, 3, 7, 9). The last member merges those two groups into (1, 2, 2, 3, 4, 5, 7, 9).

Minho wants to see the row in the middle of the work. Print the row right after the stage handled by kk members is done.

Input

The first line has the number of shops NN. NN is a power of two and 4N2204 \le N \le 2^{20}.

The second line has the taste scores of the NN shops in left-to-right order, separated by spaces. Each score is an integer between 0 and 1,000,000,000.

The third line has the number of members kk working on the current stage. kk is also a power of two and 1k<N1 \le k < N.

Output

Print the NN scores in left-to-right order on one line, separated by single spaces, as they stand right after the stage handled by kk members is done.

In that stage each member merges two sorted groups of length N/(2k)N/(2k) into one group of length N/kN/k.