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
#include<bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<=(e);i++)
#define FORD(i,s,e) for(int i=(s);i>=(e);i--)
#define ALL(k) (k).begin(),(k).end()
#define e1 first
#define e2 second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
const bool print = false;
const int MAXN = 1000;
int t[MAXN];
int zl[MAXN];

main(){
	int n,k;scanf("%d%d",&n,&k);
	FOR(i, 1, n) t[i] = i;
	int silnia = 1;
	FOR(i, 1, n) silnia *= i;
	int zli = 0;
	while(silnia > 0){
		int inversions = 0;
		int backinversions = 0;
		FOR(i, 1, n){
			FOR(j, i+1, n)
				if(t[i] < t[j]) backinversions ++;
				else inversions ++;
		}
		if(inversions == backinversions){
			/*FOR(i, 1, n) printf("%d ",t[i]);
			puts("");
			zl[t[1]]++;*/
			zli++;
			if(zli == k) {
				puts("TAK");
				FOR(i, 1, n) printf("%d ",t[i]);
				puts("");
				return 0;
			}
		}
		next_permutation(t + 1, t + n + 1);
		silnia --;
	}
	/*FOR(i, 1, n) printf("%d ",zl[i]);
	puts("");*/
	puts("NIE");
}