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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <algorithm>
#include <cmath>

const int MAX = 1e6 + 50;

void swap_halfs(int *a, int n) {
	int half = n/ 2;

	for (int i = 0; i < half; i++) {
		std::swap(a[i], a[i+half]);
	}
}

void shuffle(int *a, int n) {
	int half = n / 2;

	if (n > 2) {
		shuffle(a, half);
		shuffle(a+half, half);
	}

	swap_halfs(a, n);
}

int main() {
	int  n, t, a[MAX];

	scanf("%d %d", &n, &t);
	n = std::pow(2, n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	if (t % 2) {
		shuffle(a, n);
	}

	for (int i = 0; i < n; i++) {
		printf("%d ", a[i]);
	}
	printf("\n");

	return 0;
}