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
70
71
72
73
#include <iostream>
using namespace std;
int n, k, N, ciag[251000], uzyte[251000];
void print_ciag(){
	for(int j = 0; j < n; j++) cout << ciag[j] << " ";
	cout << endl;
}
void next(){
	int sum, l;
	for(int i = n - 1; i >= 0; i--){
		if(ciag[i] < n - i - 1){
			sum = 0;
			for(int j = n - 1; j >= i; j--) sum += ciag[j]; 
			if(sum - ciag[i] == 0) continue;
			ciag[i]++;
			sum -= ciag[i];
			l = n - 1;
			while(sum > 0){
				ciag[l] = max(0,min(n-l-1, sum));
				sum -= max(0,min(n-l-1, sum));
				l--;
			}
			while(l > i) {
				ciag[l] = 0;
				l--;
			}
			return;
		}
	}
}
void rozbij_na_ciag(){
	for(int j = 0; j < n; j++) ciag[j] = 0;
	int i = n - 1;
	while(N > 0){
		ciag[i] = min(n-i-1, N);
		N -= min(n-i-1, N);
		i--;
	}
	k--;
	while(k--) next();
}
int wolne(int plus){
	int j = 1;
	while(uzyte[j] or plus > 0) {
		if(!uzyte[j]) {
			plus--;
		}
		j++;
	}	
	uzyte[j] = 1;
	return j;
}
void generuj_z_ciagu(){
	for(int j = 0; j < n+1; j++) uzyte[j] = 0;
	for(int j = 0; j < n; j++){
		int q = wolne(ciag[j]);
		cout << q << " ";
	}
	cout << endl;
}
int main(){
	cin >> n >> k;
	N = (n * (n - 1) / 2);
	if(n < 4 or N % 2 or k > N) {
		cout << "NIE" << endl;
		return 0;
	}
	N = (n * (n - 1) / 2) / 2;
	cout << "TAK" << endl;
	rozbij_na_ciag();
	generuj_z_ciagu();
	return 0;
}