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

using namespace std;

long long n,k;
vector<int> sec;

int countInv()
{
    int ret = 0;
    for(int i = 0;i<n;i++) {
        int x = sec[i];
        for(int j = i+1;j<n;j++) {
            if(sec[j] < x) {
                ret++;
            }
        }
    }
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    long long inv = n*(n-1)/2;
    if(inv%2) {
        cout<<"NIE\n";
        return 0;
    }
    inv/=2;
    int kct = 0;
    for(int i = 1;i<=n;i++) {
        sec.push_back(i);
    }
    int fc = 1;
    int c = 2;
    while(c<=n) {
        fc*=c;
        c++;
    }
    for(int i = 0;i<fc;i++) {
        if(countInv() == inv) {
            kct++;
        }
        if(kct == k) {
            break;
        }
        next_permutation(sec.begin(), sec.end());
    }
    if(kct < k) {
        cout<<"NIE\n";
        return 0;
    }
    cout<<"TAK\n";
    for(auto it = sec.begin();it != sec.end(); it++) {
        cout<<*it<<" ";
    }
    cout<<"\n";
 }