1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<bits/stdc++.h>
using namespace std;
int tab[1<<20];
int f,g;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>f>>g;
    for(int c=0;c<(1<<f);c++){
        cin>>tab[c];
    }
    if(g%2){
        for(int c=(1<<f)-1;c>=0;c--){
            cout<<tab[c]<<" ";
        }
    }
    else{
        for(int c=0;c<(1<<f);c++){
            cout<<tab[c]<<" ";
        }
    }
}