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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.StreamTokenizer;

public class tas {

	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		     BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out))) {

			StreamTokenizer st = new StreamTokenizer(br);
			st.nextToken();
			int n = 1 << ((int) st.nval);
			st.nextToken();
			int t = (int) st.nval;


			int token;
			int[] result = new int[n];
			int i = 0;
			while (i < n) {
				token = st.nextToken();
				switch (token){
					case StreamTokenizer.TT_EOF:
						i = n;
						break;
					case StreamTokenizer.TT_NUMBER:
						result[i++] = (int) st.nval;
						break;
				}
			}

			if (t % 2 == 1){
				int temp;
				for (i = 0; i < result.length / 2; i++) {
					temp = result[i];
					result[i] = result[result.length - 1 - i];
					result[result.length - 1 - i] = temp;
				}
			}

			for (i = 0; i < n; i++){
				bw.append(String.valueOf(result[i])).append(i == n - 1 ? '\n' : ' ');
			}
		}

	}
}