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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include<bits/stdc++.h>
using namespace std;
# ifdef DEB
# define debug(...) fprintf(stderr, __VA_ARGS__)
# else
# define debug(...)
#endif
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LD long double
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define pb pop_back
#define VI vector<int>
#define VPI vector<PII>
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define ALL(x) (x).begin(), (x).end()
#define siz(V) (V.size())
#define LL unsigned long long
const LL M = 1024 * 256;
const LL inf = 1e18;

vector<LL> T[M], P[M];
vector<LL> R;
LL n, k, D[2* M];

LL get(LL a, LL b)
{
  if (b > (a * (a - 1)) / 2)
  {
    return 0;
  }
  b = min(b, (a * (a - 1)) / 2 - b);
  if (siz(T[a]) <= b)
  {
    return inf;
  }
  return T[a][b];
}

LL getP(LL a, LL p, LL k)
{
  if (p > k)
  {
    return 0;
  }
  LL aa = (a * (a - 1)) / 2;
  if (p > aa / 2)
  {
    return getP(a, aa - k, aa - p);
  }
  if (k > aa / 2)
  {
    return getP(a, p, aa / 2) + getP(a, aa - k, aa - (aa / 2 + 1));
  }
  if (siz(P[a]) > k)
  {
    LL r = P[a][k];
    if (p > 0)
    {
      r -= P[a][p - 1];
    }
    return min(r, inf);
  }
  return inf;
}

LL getInd(LL v, LL x)
{
  if (v >= M)
  {
    return v - M;
  }
  if (D[2 * v] >= x)
  {
    return getInd(2 * v, x);
  }
  return getInd(2 * v + 1, x - D[2 * v]);
}

void add(LL v, LL x)
{
  v += M;
  D[v] = x;
  while (v > 1)
  {
    v /= 2;
    D[v] = D[2 * v] + D[2 * v + 1];
  }
}

main()
{
  T[1].PB(1);
  P[1].PB(1);
  for (LL i = 2; i < M; i++)
  {
    for (LL j = 0; j <= (i * (i - 1)) / 4; j++)
    {
      LL x = get(i - 1, j);
      if (j > 0)
      {
        x += get(i, j - 1);
      }
      if (j >= i)
      {
        x -= get(i - 1, j - i);
      }
      if (x >= inf)
      {
        break;
      }
      else
      {
        T[i].PB(x);
        P[i].PB(x);
        if (siz(P[i]) > 1)
        {
          P[i][siz(P[i]) - 1] += P[i][siz(P[i]) - 2];
          //assert(P[i][siz(P[i]) - 1] <= inf * 17LL);
        }
      }
    }
  }
  
  
  scanf("%lld%lld", &n, &k);
  for (LL i = 1; i <= n; i++)
  {
    D[i + M] = 1;
  }
  for (LL i = M - 1; i > 0; i--)
  {
    D[i] = D[2 * i] + D[2 * i + 1];
  }
  LL inw = (n * (n - 1)) / 4;
  if (n % 4 == 2 || n % 4 == 3 || get(n, inw) < k)
  {
    printf("NIE\n");
    return 0;
  }
  LL left = (n * (n - 1)) / 4;
  for (LL i = n; i > 0; i--)
  {
    LL mini = 1;
    if (left > ((i - 1) * (i - 2)) / 2)
    {
      mini = left - ((i - 1) * (i - 2)) / 2 + 1;
    }
    LL st = mini;
    LL en = min(i, left + 1), mid = (st + en) / 2, r = mini - 1;
    while (st <= en)
    {
      if (getP(i - 1, left - (mid - 1), left - (mini - 1)) < k)
      {
        r = max(r, mid);
        st = mid + 1;
      }
      else
      {
        en = mid - 1;
      }
      mid = (st + en) / 2;
    }
    k -= getP(i - 1, left - (r - 1), left - (mini - 1));
    left -= r;
    LL ind = getInd(1, r + 1);
    R.PB(ind);
    add(ind, 0);
  }
  printf("TAK\n");
  for (auto r : R)
  {
    printf("%lld ", r);
  }
  printf("\n");
  return 0;
}