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
#include <stdio.h>
#include <math.h>

static const int MAX_NUMBER_OF_CARDS = 1048576;
int cards[MAX_NUMBER_OF_CARDS];

int read_int() {
    int x;
    scanf("%d", &x);
    return x;
}

int get_number_of_cards() {
    int number_of_cards_power = read_int();
    return (int) pow(2, number_of_cards_power);
}

void reverse_cards(int number_of_cards) {
    for (int i = 0; i < number_of_cards/2; ++i) {
        int temp = cards[i];
        cards[i] = cards[number_of_cards - i - 1];
        cards[number_of_cards - i - 1] = temp;
    }
}

int main() {
    int number_of_cards = get_number_of_cards(); //always a power of 2
    int number_of_repeats = read_int();
    for (int i = 0; i < number_of_cards; ++i) {
        cards[i] = read_int();
    }

    if (number_of_repeats % 2 == 1) {
        reverse_cards(number_of_cards);
    }

    for (int i = 0; i < number_of_cards; ++i) {
        printf("%d ", cards[i]);
    }
    return 0;
}