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
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class tas
{

	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int t = scanner.nextInt();
		List cards = new LinkedList();

		for(int i = 0 ; i < Math.pow(2, n); i++)
		{
			cards.add(scanner.nextInt());
		}

		for(int j = 0; j < t; j++) {
			cards = tasuj(cards);
		}

		for (Object card : cards) {
			System.out.print(card);
			System.out.print(' ');
		}

		System.exit(0);
	}

	private static List<Integer> tasuj(final List<Integer> cards) {
		if(cards.size() == 2)
		{
			Integer tmp = cards.get(0);
			cards.set(0, cards.get(1));
			cards.set(1, tmp);
			return cards;
		}
		else
		{
			final int index = cards.size() / 2;
			final List<Integer> tasuj = tasuj(new LinkedList<Integer>(cards.subList(index, cards.size())));
			final List<Integer> c = tasuj(new LinkedList<Integer>(cards.subList(0, index )));
			tasuj.addAll(c);
			return tasuj;
		}
	}
}