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
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <vector>
#include <algorithm>

template<class T>
std::ostream& operator<<(std::ostream& out, std::vector<T> v)
{
    for (auto& e : v)
        out << e << " ";
    return out;
}

std::vector<long> shuffle(std::vector<long> deck)
{
    //    std::cout << "DEBUG " << deck << '\n';

    if (deck.size() < 2)
        return deck;
    if (deck.size() == 2)
        return {deck[1], deck[0]};

    auto deckMidIt = deck.begin() + (deck.size() / 2);

    std::vector<long> firstHalf;
    std::copy(deck.begin(), deckMidIt, std::back_inserter(firstHalf));
    firstHalf = shuffle(firstHalf);

    std::vector<long> secondHalf;
    std::copy(deckMidIt, deck.end(), std::back_inserter(secondHalf));
    secondHalf = shuffle(secondHalf);

    secondHalf.insert(secondHalf.end(), firstHalf.begin(), firstHalf.end());

    return secondHalf;
}

void testing()
{
    std::vector<long> deck {1, 2, 3, 4, 5, 6, 7, 8
        //        2,4,1,5
    };
    std::cout << deck << '\n';
    std::cout << shuffle(deck) << '\n';
    std::cout << shuffle(shuffle(deck)) << '\n';

    std::reverse(deck.begin(), deck.end());
    std::cout << deck << '\n';
}

void execute()
{
    int n; // [1,20] // power for 2
    long t;// [1,10^9] // shuffle times
    std::cin >> n >> t;
    long deckSize = (long)pow(2.0, n);

    std::vector<long> deck(deckSize);

    for (long i = 0; i < deckSize; ++i)
        std::cin >> deck[i];

    if (t % 2 == 1)
        std::reverse(deck.begin(), deck.end());

    std::cout << deck;
}

int main()
{
//    testing();
    execute();
}