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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define INF 2e18
vector<ll> *dp;
const int maxw = (1<<19), w=(1<<18);
int tr[maxw];

ll getSum(ll dl, ll inv)
{
    ll x = dl*(dl-1)/2 - inv;
    x = min(x, inv);
    //if(x < 0) x = inv;
    //cout << x << endl;
    if(x < 0) return 0;
    if(x >= dp[dl].size())
        return INF;
    return dp[dl][x];
}
vector<ll> res;

bool checkp(ll n, ll k)
{
    if(n%4 != 0 && (n-1)%4 != 0)
        return false;
    ll inv = n*(n-1)/4;
    ll x = getSum(n, inv);
    if(k > x)
        return false;
    for(int i=0; i < n; i++)
    {
        for(int a=1; a <= n-i; a++)
        {
            x = getSum(n-i-1, inv+1-a);
            //cout << i << " " << a << " " << x << endl;
            if(k <= x)
            {
                res.PB(a);
                inv+=1-a;
                break;
            }
            k-=x;
        }
    }
    return true;
}
void updateTree(int a, int val)
{
    int i = a+w;
    tr[i] += val;
    i/=2;
    while(i)
    {
        tr[i] = tr[2*i] + tr[2*i+1];
        i/=2;
    }
}
int getElem(int k)
{
    int i=1;
    while(i < w)
    {
        if(tr[2*i] < k)
        {
            k-=tr[2*i];
            i = 2*i+1;
        }
        else
        {
            i = 2*i;
        }
    }
    return i-w;
}

void repRes(ll n)
{
    for(int i=0; i < maxw; i++)
    {
        tr[i] = 0;
    }
    for(int i=1; i <= n; i++)
    {
        updateTree(i, 1);
    }
    for(int i=0; i < n; i++)
    {
        res[i] = getElem(res[i]);
        updateTree(res[i], -1);
    }
//    for(int i=n-1; i >=0; i--)
//    {
//        for(int j=i+1; j < n; j++)
//        {
//            if(res[j] >= res[i])
//                res[j]++;
//        }
//    }
}

int main()
{
    //ios_base::sync_with_stdio(0);
    ll n, k;
    //cin >> n >> k;
    scanf("%lld%lld", &n, &k);
    dp = new vector<ll> [n+1];
    dp[1].PB(1);
    //int ile=0;
    for(ll i=2; i <= n; i++)
    {
        ll suma=0;
        for(ll j=0; 2*j <= i*(i-1); j++)
        {
            if(j < dp[i-1].size())
                suma+=dp[i-1][j];
            if(j >= i)
                suma-=dp[i-1][j-i];
            if(suma > INF)
                suma = INF;
            dp[i].PB(suma);
            //cout << dp[i][j] << " ";
            if(suma==INF)
                break;
        }
        //cout << endl;
    }
    if(checkp(n, k))
    {
        //cout << "TAK\n";
        printf("TAK\n");
        repRes(n);
        for(int i=0; i < res.size(); i++)
        {
            //cout << res[i] << " ";
            printf("%lld ", res[i]);
        }
    }
    else
    {
        //cout << "NIE\n";
        printf("NIE\n");
    }

    return 0;
}