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
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define INF (1 << 30)
#define SQR(a) ((a) * (a))

using namespace std;

const int N = 1111111;

int n, t;
int a[N];

void shu(int l, int r) {
    if (l == r - 1)
        return;
    shu(l, (l + r) / 2);
    shu((l + r) / 2, r);
    for (int i = 0; i < (r - l) / 2; i++) {
        swap(a[l + i], a[i + l + (r - l) / 2]);
    }
}

int main()
{
    //freopen("input.txt", "r", stdin);
    
    scanf("%d%d", &n, &t);
    n = (1 << n);

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

    t %= 2;
    if (t)
        shu(0, n);

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

    return 0;
}