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
#include<iostream>
#include<cstdio>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REV(i, n) for(int i = n-1; i >= 0; i--)

using namespace std;

int karty[1048576];

inline void readUI(int *n)
{
    register char c = 0;
    while (c < 33) c=getchar_unlocked();
    (*n) = 0;
    while (c>32)
    {
        (*n)=(*n)*10LL + (c-48);
        c=getchar_unlocked();
    }
}

inline void putUI(unsigned int n)
{
    if(n==0)
    {
        putchar_unlocked(48);
        return;
    }

    char tab[12];
    int p = 0;
    while(n != 0)
    {
        tab[p++] = (n % 10) + 48;
        n /= 10;
    }
    while(p--)
        putchar_unlocked(tab[p]);
}

int main()
{
    int n, t;
    cin >> n >> t;
    int il = pow(2, n);
    REP(i, il)
        readUI(&karty[i]);
    if(t % 2 == 0)
        REP(i, il)
        {
            putUI(karty[i]);
            putchar_unlocked(' ');
        }
    else
        REV(i, il)
        {
            putUI(karty[i]);
            putchar_unlocked(' ');
        }

    return 0;
}