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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <bitset>
#include <fstream>
using namespace std;

#define pi pair<int,int>
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define pl pair<long long,long long>
#define pb push_back
#define vi vector<int>
#define ll long long

const int MAXN=250001, mod=1e9+7;
const ll inf=1000000000000000000LL;
vector<ll> v[MAXN];
int drz[4*MAXN];

void dod(int nr, int p, int k, int co)
{
    drz[nr]++;

    if (p==k)
        return;

    int s=(p+k)/2;

    if (co<=s)
        dod(nr*2,p,s,co);
    else
        dod(nr*2+1,s+1,k,co);
}

int ilu(int nr, int p, int k, int sp, int sk)
{
    if (p==sp && k==sk)
        return drz[nr];

    int s=(p+k)/2,x=0;

    if (sp<=s)
        x=ilu(nr*2,p,s,sp,min(sk,s));

    if (sk>s)
        x+=ilu(nr*2+1,s+1,k,max(s+1,sp),sk);

    return x;
}

queue<int> q;

ll ile(int poz, ll inw)
{
    ll x=(ll)poz*(poz-1)/2+1;

    if (inw<v[poz].size())
        return v[poz][inw];

    if (x-inw-1<v[poz].size())
        return v[poz][x-inw-1];

    return inf;
}

int main ()
{
    int a,c,d,e,f,g,n,m,po,ko,sr;
    ll x,y,z,k,b;
    v[0].pb(1);

    for (a=1; a<MAXN; a++)
    {
        x=1;

        for (b=1; x && x<inf; b++)
        {
            v[a].pb(x);

            if (v[a-1].size()>b)
                x+=v[a-1][b];

            if (b>=a)
                x-=v[a-1][b-a];
        }

        if (x>=inf)
            v[a].pb(inf);
    }

    scanf("%d%lld", &n, &k);

    if (n%4==2 || n%4==3)
    {
        printf("NIE\n");
        return 0;
    }

    y=(ll)n*(n-1)/4;

    for (a=n; a; a--)
    {
        z=(ll)(a-1)*(a-2)/2;

        for (b=max(1LL,y-z+1); b<=a; b++)
        {
            x=ile(a-1,y-b+1);

            if (x>=k)
                break;
            else
                k-=x;
        }

        if (b>a)
        {
            printf("NIE\n");
            return 0;
        }

        y-=b-1;
        po=1;
        ko=n;

        while (po!=ko)
        {
            sr=(po+ko)/2;
            c=ilu(1,1,n,1,sr);

            if (sr-c<b)
                po=sr+1;
            else
                ko=sr;
        }

        q.push(po);
        dod(1,1,n,po);
    }

    printf("TAK\n");

    for (; !q.empty(); q.pop())
        printf("%d ", q.front());

    return 0;
}