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 <iostream>
#include <vector>
#include <algorithm>

int main()
{
    int n, t;

    std::cin >> n >> t;
    int m = 1 << n;

    std::vector<int> V(m, 0);

    for (int i=0;i<m;i++)
        std::cin >> V[i];

    if ( t % 2 )
        std::reverse( V.begin(), V.end() );

    for (auto num : V)
        std::cout << num << " ";

    std::cout << std::endl;
    return 0;
}