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
#include <iostream>
#include <list>

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::uint_fast32_t n;
    std::uint_fast32_t t;
    std::cin >> n >> t;
    if (t % 2 == 0)
    {
        std::uint_fast32_t a_i;
        std::cin >> a_i;
        std::cout << a_i;
        for (std::uint_fast32_t i = (1 << n); i > 1; i--)
        {
            std::cin >> a_i;
            std::cout << " " << a_i;
        }
    }
    else
    {
        std::list<std::uint_fast32_t> a;
        std::uint_fast32_t a_i;
        for (std::uint_fast32_t i = (1 << n); i > 1; i--)
        {
            std::cin >> a_i;
            a.push_back(a_i);
        }
        std::cin >> a_i;
        std::cout << a_i;
        for (auto it = a.rbegin(); it != a.rend(); it++)
        {
            std::cout << " " << *it;
        }
    }
    std::cout << "\n";
}