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
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
	int n, t, a;
	scanf("%d %d", &n, &t);
	n = (1 << n);

	vector<int> cards;
	cards.reserve(n);

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

	if (t % 2) {
		for (vector<int>::reverse_iterator it = cards.rbegin(); it != cards.rend(); ++it) {
			printf("%d ", *it);
		}
	}
	else {
		for (vector<int>::iterator it = cards.begin(); it != cards.end(); ++it) {
			printf("%d ", *it);
		}
	}

	return 0;
}