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
#include <cstdio>
#include <cmath>
#include <utility>

int tab [2000000];

void shuffle (int *deck, int len)
{
    if (len == 2)
    {
        std::swap (deck [0], deck [1]);
        return;
    }
    shuffle (deck, len/2);
    shuffle (deck + (len/2), len/2);
    for (int i = 0; i < len/2; ++ i)
    {
        std::swap (deck [i], deck [i + len/2]);
    }
}

int main ()
{
    int n;
    int t;
    scanf ("%d %d", &n, &t);
    t %= 2;
    n = pow (2, n);
    for (int i = 0; i < n; ++ i)
    {
        scanf ("%d", &tab [i]);
    }
    if (t)
        shuffle (tab, n);
    for (int i = 0; i < n; ++ i)
        printf ("%d ", tab [i]);
    printf ("\n");
    return 0;
}