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

public class tas {

    public static void main(String[] args) {
	// write your code here
        tasowanie();
    }

    public static void tasowanie() {
        final Scanner sc = new Scanner(System.in);
        final long exponent = sc.nextLong();
        final long numberOfShuffles = sc.nextLong();
        long[] numbers = new long[(int) Math.pow(2, (int) exponent)];
        for(int i = 0; i < numbers.length; i++) {
            numbers[i] = sc.nextLong();
        }

        boolean even = numberOfShuffles % 2 == 0;
        if (even) {
            for (int i = 0; i < numbers.length; i++) {
                if (i != 0)
                    System.out.print(" ");
                System.out.print(numbers[i]);
            }
        }
        else {
            for (int i = numbers.length -1; i >= 0; i--) {
                if (i != numbers.length - 1)
                    System.out.print(" ");
                System.out.print(numbers[i]);
            }
        }

    }
}