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
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define repLL(i,a,b) for(LL i=(LL)a;i<(LL)b;i++)
#define perLL(i,a,b) for(LL i=(LL)a;i>(LL)b;i--)
#define debug5(a,b,c,d,e) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<" "<<#e<<": "<<e<<endl;
#define debug4(a,b,c,d)  cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<" "<<#d<<": "<<d<<endl;
#define debug3(a,b,c) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
#define debug2(a,b) cerr<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define debug(a) cerr<<#a<<": "<<a<<endl;
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

const int maxn=(120)+7;
const int inf=(1e9)+7;
const LL LLinf=((2e18)+7LL);
const LD eps=1e-9;
const LL mod=1e9+7;

// ***************************** CODE ***************************** //

LL dp[maxn][maxn*maxn];
LL dyn[250007][20];
int pot=(1<<20);
int tree[(1<<21)+7];

int kta(int wierz,int lewo,int prawo,int val)
{
      // cout<<wierz<<" "<<lewo<<" "<<prawo<<" "<<tree[2*wierz]<<endl;
      if(lewo==prawo)
            return lewo;
      if(tree[2*wierz]>=val)
            return kta(2*wierz,lewo,(prawo+lewo)/2,val);
      return kta(2*wierz+1,(lewo+prawo)/2+1,prawo,val-tree[2*wierz]);
}

void dodaj(int x,int val)
{
      x+=pot;
      while(x>0)
      {
            tree[x]+=val;
            x/=2;
      }
}

LL ile(LL n,LL k)
{
      if(k>n*(n-1)/2)
            return 0LL;
      if(n<=100)
            return dp[n][k];
      if(k>=15)
            k=n*(LL)(n-1LL)/2LL-k;
      if(k>=15 || k<0LL)
            return LLinf;
      // return 1LL;
      return dyn[n][k];
      // cout<<endl<<n<<" "<<k<<endl;
      // exit(0);
}

int main()
{
      _upgrade
      int N=100;
      dp[0][0]=1;
      rep(i,1,N+1)
      {
            rep(j,0,i*(i-1)/2+1)
            {
                  rep(k,0,i)
                  {
                        dp[i][j]+=dp[i-1][j-k];
                        dp[i][j]=min(dp[i][j],LLinf);
                  }
                  // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
            }

      }
      LL n;
      LL k;
      cin>>n>>k;
      rep(i,1,n+5)
      {
            rep(j,0,15)
            {
                  if(i==1)
                        dyn[i][j]=dp[i][j];
                  else
                        rep(K,0,min(j+1,i))
                        {
                              dyn[i][j]+=dyn[i-1][j-K];
                              dyn[i][j]=min(dyn[i][j],LLinf);
                        }
            }
      }

      if(n%4!=0 && n%4!=1)
      {
            cout<<"NIE\n";
            return 0;
      }
      if(ile(n,n*(n-1)/4)<k)
      {
            cout<<"NIE\n";
            return 0;
      }

      LL curr=n*(n-1LL)/4LL;

      rep(i,1,pot)
            dodaj(i,1);
      cout<<"TAK\n";
      rep(i,0,n)
      {
            rep(liczba,1,n-i+1)
            {
                  if(ile(n - i - 1, curr)==0LL)
                  {
                        // cout<<ile(n-i-1,curr)<<endl;
                        LL roz=curr-((n-i-1)*(n-i-2))/2LL;
                        liczba+=roz;
                        curr-=roz;
                        // cout<<ile(n-i-1,curr)<<endl;
                  }
                  // assert(curr-liczba+1>=0);
                  // cout<<n-i-1<<" "<<curr<<endl;
                  if( ile( n - i - 1 , curr ) >= k )
                  {
                        int a=kta(1,0,pot-1,liczba);
                        dodaj(a,-1);
                        cout<<a<<" ";
                        break;
                  }
                  else
                  {
                        k-=ile( n - i - 1, curr );
                        curr--;
                  }
            }
            // debug2(k,curr);
      }
      cout<<endl;
      // cout<<k<<" "<<curr<<endl;
      return 0;
}