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
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int n;
long long k;

long long dp1[107][5007];
long long inf = 1.1e18;
int res1[107];

void maly() {
    dp1[0][0] = dp1[1][0] = 1;
    for(int i = 2; i <= n; ++i) {
        for(int j = 0; 2 * j <= i * (i - 1); ++j) {
            for(int a = 1; a <= min(i, j + 1); ++a) {
                dp1[i][j] += dp1[i - 1][j - a + 1];
                if(dp1[i][j] > inf) {
                    dp1[i][j] = inf;
                    break;
                }
            }   
        }
    }
    
    int inws = (n * (n - 1)) / 4;
    if(dp1[n][inws] < k) {
        cout << "NIE\n";
        return;
    }
    
    for(int i = 1; i <= n; ++i) {
        res1[i] = 1;
        while(dp1[n - i][inws - res1[i] + 1] < k) {
            k -= dp1[n - i][inws - res1[i] + 1];
            res1[i]++;
        }
        
        inws -= res1[i] - 1;
    }
    
    for(int i = n; i > 0; --i) {
        for(int j = i + 1; j <= n; ++j) if(res1[j] >= res1[i]) res1[j]++;
    }
    
    cout << "TAK\n";
    for(int i = 1; i <= n; ++i) cout << res1[i] << ' ';
    cout << endl; 
}

const int N = 250000;
const int K = 32;
long long dp[N + 7][K];
int res[N + 7];
int add[N + 7];

void duzy() {
    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j < K; ++j) {
            for(int d = 0; d <= min(j, i); ++d) {
                dp[i][j] += dp[i - 1][j - d];
                if(dp[i][j] > inf) {
                    dp[i][j] = inf;
                    break;
                }
            }
        }
    }    
    
    int d = 0;
    long long sum = 0;
    long long inws = (long long) n * (n - 1);
    inws /= 4;
    
    while(sum < inws) {
        d++;
        sum += d;
    }   
    
    int wolne = sum - inws;
    if(wolne >= K || dp[d][wolne] >= k) {
        for(int i = d + 2; i <= n; ++i) res[i] = 0;    
        for(int i = d + 1; i > 1; --i) {
            res[i] = i - 1 - wolne;
            wolne = 0;
            while(dp[i - 2][wolne] < k) {
                k -= dp[i - 2][wolne];
                wolne++;
                res[i]++;
            }
        }
        res[1] = 0;
    }
    else {
        for(int i = d + 3; i <= n; ++i) res[i] = 0;
        k -= dp[d][wolne];
        res[d + 2] = 1;
        wolne++;
        while(dp[d][wolne] < k) {
            k -= dp[d][wolne];
            wolne++;
            res[d + 2]++;
        }
        
        for(int i = d + 1; i > 1; --i) {
            res[i] = i - 1 - wolne;
            wolne = 0;
            while(dp[i - 2][wolne] < k) {
                k -= dp[i - 2][wolne];
                wolne++;
                res[i]++;
            }
        }
        res[1] = 0;
    }
    
    reverse(res + 1, res + n + 1);
    
    int maxi = 0;
    
    int ile = 0;
    for(int i = n; i > 0; --i) {
        if(res[i] > 0) {
            if(res[i] <= maxi) {
                maxi = 0;
                ile++;
                for(int j = i + 1; j <= n; ++j) {
                    add[j] += add[j - 1];
                    res[j] += add[j];
                }
                for(int j = i + 1; j <= n; ++j) {
                    add[j] = 0;
                    if(res[j] >= res[i]) res[j]++;
                    maxi = max(maxi, res[j]);
                }
            }
        }
        else {
            maxi++;
            add[i + 1]++;
        }
        maxi = max(maxi, res[i]);
    }
    for(int i = 1; i <= n; ++i) {
        add[i] += add[i - 1];
        res[i] += add[i];
    }
    cout << "TAK\n";
    for(int i = 1; i <= n; ++i) cout << res[i] + 1 << ' ';
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> k;
    long long inws = (long long) n * (n - 1);
    if(inws % 4 != 0) {
        cout << "NIE\n";
        return 0;
    }
    if(n <= 100) maly();
    else duzy();
    return 0;
}