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
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <list>
#include <math.h>

using namespace std;


int main()
{
	int n;
	int t;
	int n2;
	cin >> n;
	cin >> t;
	n2 = (int)pow(2, n);

	int* arr = new int[n2];
	for (int i = 0; i < n2; i++)
	{
		cin >> arr[i];
	}
	if (t % 2 == 0)
	{
		for (int i = 0; i < n2; i++)
		{
			cout << arr[i] << " ";
		}
	}
	else
	{
		for (int i = n2-1; i >= 0; i--)
		{
			cout << arr[i] << " ";
		}
	}

    return 0;
}