1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  int n,t;
  std::cin >> n >> t;
  
  int N = (1 << n);
  std::vector<int> a(N);
  for (int i=0; i<N; ++i)
    std::cin >> a[i];

  // Every "shuffle" is reverse.
  // Every two reverses nullifies.
  // Reverse if odd number of shuffles.

  int reverse = t%2;
  if (reverse > 0)
    std::reverse(a.begin(), a.end());

  std::cout << a[0];
  for (int i=1; i<N; ++i)
    std::cout << ' ' << a[i];
  std::cout << std::endl;

  return 0;
}