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

using namespace std;

int main(){
   ios::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
int64_t p=1,x=1;
   int l=0,f=0;
cin >> n>>k;

  
  if(((n*(n-1))/2)%2==0 ){
    if(n==1 and k==1){cout << "TAK" << '\n'<<1<<'\n';}
    else{
    vector <int> v(n);
    for(int i=0; i<n; i++){
      v[i]=i;
     }
     for(int i=2; i<=n; i++){
      p=p*i;
     }
     while(x<p){
      l=0;
      x++;
      next_permutation(v.begin(), v.end());
      for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
          if(v[i]>v[j]){l++;}
        }
      }
      if(l==((n*(n-1))/4)){k--;}
      if(k==0){
      f=1;
      cout << "TAK"<<'\n';
        for(int i=0; i<n; i++){
          cout << v[i]+1<<' ';
        }
        x=p;
      }
     }
     if(f==0){cout << "NIE"<<'\n';}
     
     }
     
  }
  else{cout << "NIE"<<'\n';}




return 0;
}