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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//no comment needed
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
#include <strings.h>
#include <math.h>
#include <time.h>
#include <map>
#include <climits>
using namespace std;

//Two of the most frequently used typical of long names, make life easier
typedef vector<int> VI;
typedef long long LL;

/* HEADERS */

/* Loops */
// FOR - loop increasing 'x' from 'b' to 'e' inclusive
#define FOR(x, b, e) for(int x = b; x <= (e); ++x)
// FORD - loop decreasing 'x' from 'b' to 'e' inclusive
#define FORD(x, b, e) for(int x = b; x >= (e); --x)
// REP - loop increasing 'x' from '0' to 'n'. Used to search and build DS
#define REP(x, n) for(int x = 0; x < (n); ++x)
// Clone long type of 'n'
#define VAR(v, n) __typeof(n) v = (n)
// ALL(c) represents the pair of iterators, indicating begin-end elements in the STL DS
#define ALL(c) (c).begin(), (c).end()
//Macro to get size of STL DS, used to avoid compilation warrning with int and uint comp
#define SIZE(x) ((int)(x).size())
// Very profitable macro aimed to iterate through all elements of STL DS
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

/* Shortcuts for vectors most common use cases*/
#define PB push_back
#define POP pop_back
#define ST first
#define ND second
#define RM( v, x )  v.erase(v.begin() + x)
#define PF( v, x )  v.insert(v.begin(), x);
#define FIND(v, x)  find(v.begin(), v.end(), x)
#define Vit         std::vector<int>::iterator

/* some other usefull methods */
#define INF     INT_MAX/2-256
#define _il     inline
#define _ili    inline int
#define _ilv    inline void

#define IN      "test_org.in"
#define OUT     "test.out"
#define ERR     "sample.err"

_ilv sol(VI&, int, int );
//debug print
void print_v(VI v){
fprintf(stderr, "vec:: ");
    FOREACH(it, v)
        fprintf(stderr, "%d, ", *it);
fprintf(stderr, "\n");
}

int main(){
//    freopen(IN,  "r", stdin);
//    freopen(OUT, "w", stdout);
//    freopen(ERR, "w", stderr);

    int n, t; cin >> n; cin >> t;
    int N = 1 << n;
VI deck;
    REP(x, N){
        int c; cin >> c;
        deck.push_back(c);
    }

    REP(tt, t){
        sol(deck, n, N); //run sol
    }
    FOREACH(it, deck)
        fprintf(stdout, "%d ", *it);
    return 0;
}

_ilv sol(VI &deck, int n, int N)
{
    //do work
    for(int i=0; i<N; i+=2){
        int tmp = deck[i];
        deck[i] = deck[i+1];
	deck[i+1] = tmp;
    }
//print_v(deck);
//fprintf(stderr, "------- copying: \n");
    for(int i=1; i<n; i++){
	int nn = 1<<i;
	VI tmp(nn);
//fprintf(stderr, "#: copy for i=%d, nn=%d \n", i, nn);
	for(int x=0; x<N-nn; x+=2*nn){
		//copy to tmp
//fprintf(stderr, "###: x= %d \n", x);
		for(int j=0;j<nn;j++)
			tmp[j] = deck[j+x];
//fprintf(stderr, "###: tmp: \n");
//print_v(tmp);
		for(int j=0;j<nn;j++)
			deck[j+x]=deck[j+x+nn];
//fprintf(stderr, "###: deck: \n");
//print_v(deck);
		for(int j=0;j<nn;j++)
			deck[j+x+nn]=tmp[j]; 	
//fprintf(stderr, "###: deck: \n");
//print_v(deck);
	}
    }
}