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

using namespace std;

const int MAX_CARD_AMOUNT = 1048576 + 10;

int card[MAX_CARD_AMOUNT];
int cardsAmount = 1, n, t;

void countCardsAmount() {
    for (int i = 0; i < n; ++i) {
        cardsAmount *= 2;
    }
}

void readInput() {
    scanf("%d %d", &n, &t);

    countCardsAmount();

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

void printResult() {
    for (int i = 0; i < cardsAmount; ++i) {
        printf("%d ", t % 2 == 0 ? card[i] : card[cardsAmount - i - 1]);
    }
}

int main() {
    readInput();
    printResult();
    return 0;
}