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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <cstdio>
#include <vector>
#include <algorithm>

std::vector<int> rek(std::vector<int> vec, int n) {
	
	if (0) {
		fprintf(stderr, "n = %d\nvec = {", n);
		for (auto it : vec)
			fprintf(stderr, "%d ", it);
		fprintf(stderr, "}\n");
	}

	if (n == 1) {
		std::swap(vec[0], vec[1]);
		return vec;
	}
	std::vector<int> A(1<<(n-1)), B(1<<(n-1)), C(1<<n);
	
	auto itV = vec.begin();
	
	for (auto itA = A.begin(); itA != A.end(); ++itA, ++itV)
		*itA = *itV;
	for (auto itB = B.begin(); itB != B.end(); ++itB, ++itV)
		*itB = *itV;

	if (0) {
		fprintf(stderr, "A = {");
		for (auto it : A) 
			fprintf(stderr, "%d ", it);
		fprintf(stderr, "}\nB = {");
		for (auto it : B) 
			fprintf(stderr, "%d ", it);
		fprintf(stderr, "}\n");
		
	}

	A = rek(A, n - 1);
	B = rek(B, n - 1);

	auto it = C.begin();
	for (int i = 0; i < (int)B.size(); ++i, ++it)
		*it = B[i];
	for (int i = 0; i < (int)A.size(); ++i, ++it) 
		*it = A[i];

	return C;
}


int main() {
	int n, t;
	scanf("%d%d", &n, &t);
	std::vector<int> vec((1<<n));
	for (int i = 0; i < (1<<n); ++i) {
		scanf("%d", &vec[i]);
	}
	
	if (t % 2)
		vec = rek(vec, n);

	for (auto it : vec) printf("%d ", it);

	return 0;
}