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
//#include "stdafx.h"
//#include <conio.h>
#include <string>
#include <iostream>
#include <cmath>
using namespace std;


void tasujj(int n, int t, string &k)
{
	//czyGlowna(n);
	int ileKart = pow(2, n);
	int polowa = ileKart / 2;
	if (ileKart <= 2)
		t--;
	string k1 = "";
	string k2 = "";
	string nowaKolejnosc = "";

	if (t > 0)
	{
		for (int i = (polowa * 2); i < (ileKart * 2); i += 2)
		{
			k1 += k[i];
			k1 += " ";
		}
		for (int i = 0; i < (polowa * 2); i += 2)
		{
			k2 += k[i];
			k2 += " ";
		}

		tasujj(n-1, t, k1);
		tasujj(n-1, t, k2);		

		nowaKolejnosc = k1 + k2;
		k = nowaKolejnosc;
	}
	
}

void tasuj(int n, int t, string &k)
{
	int ileRazy = t;
	while (ileRazy > 0)
	{		
		tasujj(n, t, k);
		ileRazy--;
	}
}


int main()
{
	string dane;                 
	getline(cin, dane);	

	string karty;           
	getline(cin, karty);

	int n = (int)dane[0] - '0';
	int t = (int)dane[2] - '0';

	tasuj(n, t, karty);
	cout << karty;	
	
	//_getch();
    return 0;
}