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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <stdio.h>

#define BUF_READ 15000000
#define BUF_BORDER 100
#define BUF_SIZE (BUF_READ+BUF_BORDER+1)

char buf[BUF_SIZE];
char *buf_cur;
char *buf_end;
int file_finished;
unsigned int bytes_write;

int buf_init()
{
        int bytes_read;
        
        bytes_read = fread( buf, 1, BUF_READ, stdin );
        buf_cur = buf;
        buf_end = buf + bytes_read;
        if (bytes_read < BUF_READ) {
                file_finished = 1;
        } else {
                file_finished = 0;
        }

        return bytes_read;
}

void buf_findNextNumber()
{
        while ( *buf_cur < '0' || *buf_cur > '9') {
                buf_cur++;
        }
}

void read_buffer_if_needed(int border)
{
        int i, d, bytes_read;

        if (file_finished == 1) {
                return;
        }

        d = buf_end - buf_cur;
        if (d > border) {
                return;
        }

        for(i = 0; i < d; ++i) {
                buf[i] = buf_cur[i];
        }

        bytes_read = fread( buf+d, 1, BUF_READ, stdin );
        if (bytes_read < BUF_READ) {
                file_finished = 1;
        }
        buf_cur = buf;
        buf_end = buf+d+bytes_read;

}

unsigned int buf_getNextNumber()
{
        unsigned int number = 0;

        read_buffer_if_needed(BUF_BORDER);

        buf_findNextNumber();
        number = *buf_cur - '0';
        buf_cur++;
        while( *buf_cur >= '0' && *buf_cur <= '9') {
                number = number*10 + *buf_cur - '0';
                buf_cur++;
        }
        return number;        
}

void buf_reset()
{
        buf_cur = buf;
        bytes_write = 0;
}

void buf_write_int(unsigned int a)
{
        char l_buf[12];
        int i;

        i = 0;
        while(a > 0) {
                l_buf[i] = (a % 10) + '0';
                a /= 10;
                i++;
        }

        i--;
        while(i >= 0) {
                *buf_cur++ = l_buf[i--];
                bytes_write++;
        }
        *buf_cur = ' ';
        buf_cur++;
        bytes_write++;
}

unsigned int pow2(unsigned int exp)
{
        unsigned int result = 1;
        unsigned int base = 2;

        while (exp) {
                if (exp & 1) {
                        result *= base;
                }
                exp >>= 1;
                base *= base;
        }

        return result;
}

int main()
{
        unsigned int n, t;
        int bytes_read, i;
        unsigned int tab[1048576];

        scanf("%u %u\n", &n, &t);
        n = pow2(n);

        bytes_read = buf_init();

//        printf("%d\n", bytes_read);

        if (t % 2 == 0) {
                fwrite( buf, 1, bytes_read, stdout );
                return 0;
        }

        for(i = 0; i < n; ++i) {
                tab[i] = buf_getNextNumber();
        }

        buf_reset();
        for(i = n-1; i >= 0; --i) {
                buf_write_int(tab[i]);
        }
        buf_cur--;
        *buf_cur++ = '\n';
        *buf_cur = '0';
//        printf("%d\n", bytes_write);
        fwrite( buf, 1, bytes_write, stdout );

        return 0;
}