1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;

/**
 * Created by stawicad on 2016-11-21.
 */
public class tas {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt() & 1;
        int length = 1 << n;
        int[] input = new int[length];
        for (int i = 0; i < length; i++) {
            input[i] = sc.nextInt();
        }
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < length; i++) {
            result.append(input[(1 - t) * i + t * (length - i - 1)]).append(' ');
        }
        System.out.println(result.toString());
    }

}