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
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_N = 100000;

int t[MAX_N];
int n;
long long k;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> k;
	for (int i = 0; i < n; i++)
		t[i] = i + 1;

	long long ilosc = 0;
	if (n * (n - 1) % 4 == 0)
		while (true)
		{
			long long ile = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					if (t[i] > t[j])
						ile++;
				}
			}

			if (ile * 4 == n*(n - 1))
			{
				ilosc++;
				if (ilosc == k)
				{
					cout << "TAK\n";
					for (int i = 0; i < n; i++)
						cout << t[i] << " ";
					return 0;
				}
			}
			int i = n - 1;
			while (i > 0 && t[i - 1] >= t[i])
				i--;
			if (i == 0)
				break;
			int j = i;
			while (j < n && t[j] > t[i - 1])
				j++;
			j--;
			swap(t[i - 1], t[j]);
			reverse(t + i, t + n);
		}

	cout << "NIE\n";
	return 0;
}