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>
#include <vector>

using namespace std;

long long /*tab[100][10000],*/ n, k, lol,z, tb[250001], c, stop , bmin[250001];
vector <int>kon;
vector <long long> tab[250001];
int tko[524289];
long long wyn(long long a, long long b)
{
    if(tab[a].size()==0){bmin[a]=b;tab[a].push_back(0);}
    if(bmin[a]-tab[a].size()<=b)tab[a].push_back(0);
    if(b==0){k--;if(k==0)stop=1;return 1;}
    if(a*(a-1)<2*b)return 0;
    if(tab[a][bmin[a]-b]!=0&&k>tab[a][bmin[a]-b])
    {
        k-=tab[a][bmin[a]-b];
        return tab[a][bmin[a]-b];
    }
    if(stop==1)return tab[a][bmin[a]-b];
    for(int i=0;i<a;i++)
    {
        tb[a]=i;
        c=wyn(a-1,b-i);
        tab[a][bmin[a]-b]+=c;
        if(stop==1)break;
        tb[a]=0;
        if(i==b)break;
    }
    return tab[a][bmin[a]-b];
}


int main()
{
    ios_base::sync_with_stdio();
    cin>>n;
    cin>>k;
    if(n%4>1)cout<<"NIE";
    else
    {
        lol=wyn(n,(n*(n-1))/4);

    if(stop==0)cout<<"NIE";
    else
    {
    cout<<"TAK"<<endl;
    for(int i=0;i<n;i++)
    {
        tko[262144+i]=1;
    }
    for(int i=262143;i>=1;i--)tko[i]=tko[2*i]+tko[2*i+1];
    for(int i=n;i>0;i--)
    {
    tb[i]++;
    z=1;
    for(;z<262144;)
    {
        if(tko[2*z]>=tb[i])z=2*z;
        else
        {
            tb[i]-=tko[2*z];
            z=2*z+1;
        }
    }
    cout<<z-262143<<" ";
    for(;z>=1;z/=2)
    {
        tko[z]--;
    }
    }}}
}