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
#include <cstdio>
#include <vector>
using namespace std;

template<class T>
void out(T first, T last) {
    while(first != last)
        printf("%u ", *(first++));
}

int main() {
    unsigned n, t, a;
    scanf("%u%u", &n, &t);
    n = 1u << n;
    vector<unsigned> cards;
    cards.reserve(n);
    while(n--) {
        scanf("%u", &a);
        cards.emplace_back(a);
    }
    if(t % 2 == 0)
        out(cards.begin(), cards.end());
    else
        out(cards.rbegin(), cards.rend());
}