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
#include <bits/stdc++.h>
using namespace std;

const int ac = 1e5;
int A[ac];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long n, k; cin >> n >> k;
	if (n * (n - 1) % 4 != 0) { cout << "NIE\n"; return 0; }
	for (int i = 0; i < n; i++) A[i] = i;
	long long g = 0;
	do
	{
		int c = 0;
		for (int i = 0; i < n; i++)
	    		for (int j = i + 1; j < n; j++)
			{
				c += (A[i] > A[j]);
			}
		if (n * (n - 1) % 4 == 0 && c == n * (n - 1) / 4)
		{
			g++;
			if (g == k)
			{ cout << "TAK\n"; for (int i = 0; i < n; i++) cout << A[i] + 1 << ' ';
				cout << '\n'; return 0; }
		}
	}
	while (next_permutation(A, A + n));
	cout << "NIE\n";
}