#P11603. Recursive Card Shuffle

    ID: 13698 Type: Default 1000ms 256MiB

Recursive Card Shuffle

Recursive Card Shuffle

Given a deck of \(2^n\) cards, where the \(i\)-th card contains a positive integer \(a_i\), you need to simulate a recursive shuffle process defined as follows:

  • If the number of cards is \(1\), do nothing.
  • If there are \(2^k\) cards (with \(k \ge 1\)), then:
    • Recursively shuffle the first \(2^{k-1}\) cards and the last \(2^{k-1}\) cards.
    • Place the shuffled second half before the shuffled first half.

Shuffling the full deck once using the above process is considered one shuffle.

Given an integer \(t\), determine the order of the deck after performing \(t\) shuffles.

Note: It can be proven by induction that one shuffle simply reverses the order of the deck. Therefore, if \(t\) is odd, the final order is the reverse of the original order, and if \(t\) is even, the order remains the same.

inputFormat

The first line contains two integers \(n\) and \(t\) where \(2^n\) is the number of cards and \(t\) is the number of shuffles. The second line contains \(2^n\) positive integers \(a_1, a_2, \ldots, a_{2^n}\) representing the initial order of the cards.

outputFormat

Output the order of the \(2^n\) cards after performing \(t\) shuffles. The numbers should be separated by a single space.

sample

1 1
1 2
2 1