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
52
53
54
55
56
57
58
59
60
import java.io.*;
import java.util.StringTokenizer;

/**
 * Created by Lukasz.Dobrzynski on 16/11/21.
 */
public class tas {

    private int sizeOfInput;
    private boolean reverse;
    private StringBuilder builder;
    private String[] data;

    public static void main(String[] args) {
        tas app = new tas();
        try {
            app.readInput();
            app.writeOutput();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void writeOutput() throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        for (int i = 0; i < sizeOfInput - 1; i++) {
            bw.write(data[i]);
            bw.write(" ");
//            builder.append(data[i]);
//            builder.append(" ");
        }
        bw.write(data[sizeOfInput - 1]);
        bw.write("\n");
        bw.flush();
//        System.out.println("Adadfaf");
//        builder.append(data[sizeOfInput - 1]);
//        System.out.println(builder);
    }

    private void readInput() throws IOException {
        try (BufferedReader r = new BufferedReader(new InputStreamReader((System.in)))) {
//        try (BufferedReader r = new BufferedReader(new FileReader("test.in"))) {
            StringTokenizer tokenizer = new StringTokenizer(r.readLine());
            sizeOfInput = (1 << (int) Integer.parseInt(tokenizer.nextToken()));
            reverse = Integer.parseInt(tokenizer.nextToken()) % 2 == 1;
            data = new String[sizeOfInput];
            builder = new StringBuilder((int) (sizeOfInput * Math.log10(sizeOfInput)));
            tokenizer = new StringTokenizer(r.readLine());

            for (int i = 0; i < sizeOfInput; i++) {
                int indexToAdd = i;
                if (reverse) {
                    indexToAdd = sizeOfInput - 1 - i;
                }
                data[indexToAdd] = tokenizer.nextToken();
            }
        }
    }
}