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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class tas {

    static int[] readIntsLine(BufferedReader reader, int amount) throws IOException {
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int[] result = new int[amount];
        for (int i = 0; i < amount; i++) {
            result[i] = Integer.parseInt(tokenizer.nextToken());
        }
        return result;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int[] line = readIntsLine(reader, 2);
        int n = line[0];
        int t = line[1];
        int cards[] = readIntsLine(reader, (int) Math.pow(2, n));
        boolean reverse = t % 2 != 0;

        if (reverse) {
            for (int i = cards.length - 1; i >= 0; i--) {
                System.out.print(cards[i]);
                System.out.print(' ');
            }
        } else {
            for (int i = 0; i < cards.length; i++) {
                System.out.print(cards[i]);
                System.out.print(' ');
            }
        }
        System.out.println();
    }

}