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
#include <vector>
#include <math.h>
#include <string>
#include <iostream>
#include <sstream>
#include <limits>

//#define PA2016_TEST

#ifdef PA2016_TEST
#define ASSERT( condition ) if ( !( condition ) ) { __debugbreak(); }
#define PAUSE_CONSOLE system( "pause" );
#define DEBUG_ONLY( line ) line;
#else
#define ASSERT( condition )
#define PAUSE_CONSOLE 
#define DEBUG_ONLY( line )
#endif


int main()
{
	unsigned int cardsPower = 0;
	unsigned int numOfShakeUps = 0;

	std::cin >> cardsPower;
	std::cin >> numOfShakeUps;

	unsigned int numberOfCards = ( 1 << cardsPower );

	std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

	// Read cards
	// This reading looks silly but should be enough.
	unsigned int readInt;
	std::vector<unsigned int> answer;
	answer.reserve( numberOfCards );
	std::string line;
	std::getline( std::cin, line );
	std::istringstream iss( line );
	while( iss >> readInt )
	{
		answer.push_back( readInt );
	}

	// Swap cards if needed:

	if( numOfShakeUps & 1 )
	{
		const auto size = answer.size();
		const auto sizeDivided = size / 2;
		for( int i = 0; i < sizeDivided; ++i )
		{
			std::swap( answer[ i ], answer[ size - i - 1 ] );
		}
	}

	for( auto num : answer )
	{
		std::cout << num << " ";
	}

	return 0;
}