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
import java.util.Scanner;

public class tas {

    private static int[] cards = new int[1048576];

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        int n = s.nextInt();
        int t = s.nextInt();
        int cardsCount = pow2(n);

        for (int i = 0; i < cardsCount; i++) {
            cards[i] = s.nextInt();
        }

        if (t % 2 == 0) {
            for (int i = 0; i < cardsCount - 1; i++) {
                System.out.print(cards[i]);
                System.out.print(" ");
            }
            System.out.println(cards[cardsCount - 1]);
        } else {
            for (int i = cardsCount - 1; i > 0; i--) {
                System.out.print(cards[i]);
                System.out.print(" ");
            }
            System.out.println(cards[0]);
        }
    }

    private static int pow2(int n) {
        int result = 2;
        while (n > 1) {
            n--;
            result *= 2;
        }
        return result;
    }
}