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
184
185
186
187
188
189
190
191
192
193
194
195
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define int long long
#define st first
#define nd second
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define mt make_tuple
#define e(a, b) get<b>(a)
#define inf 1000000000000050000LL
using namespace std;
using namespace __gnu_pbds;


typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

ordered_set S;

vector<int> M[260400];
int W[1000020];
int N=1;
int f(int n, int k)
{
	//cout<<"f";
	if (k>n*(n-1)/2)
		return 0;
	if (k*4-7>n*(n-1))
		return f(n,n*(n-1)/2-k);
	if (k>=M[n].size())
		return inf;
	return M[n][k];
}
void insert(int p, int q)
{
	//cout<<"i";
	p+=N-1;
	W[p]=q;
	p/=2;
	for (;p>0; p/=2)
		W[p]=W[2*p]+W[2*p+1];
	return;
}
int query(int p)
{
	//cout<<"q";
	int w=1, kt=p;
	if (W[w]<=kt)
		return -1;
	while(w<N)
	{
		if (W[2*w]>kt)
		{
			w*=2;
		}
		else
		{
			kt-=W[2*w];
			w=2*w+1;
		}
	}
	return w-N+1;
}
void g(int n, int linw, int k)
{
	//cout<<"g";
	//cout<<n<<" "<<linw<<" "<<k<<"\n";
	/*if (n<0 || linw<0 || k<0)
		return;*/
	if (n==0)
		return;
	int l=max(0LL, linw-(n-2)*(n-1)/2);
	//cout<<n<<" "<<linw<<" "<<k<<" "<<"l="<<l<<"   ";
	while(f(n-1, linw-l)<k)
	{
		k-=f(n-1, linw-l);
		/*if (f(n-1, linw-l)<0)
			return;*/
		l++;
		if (l>linw)
			return;
	}
	//cout<<l;
	int l0=l;
	
	//l=query(l);
	auto pom=S.find_by_order(l);
	if (pom==S.end() || l0<0)
	{
		cout<<"AAAAA\nAAAAAA\nAAAAAAAAAAAAAAAAAAAAA\n";
		return;
	}
	l=*S.find_by_order(l);
	
	cout<<l<<" ";
	//cout<<"o";
	/*if (l==-1)
		return;*/
	//cout<<l<<" ";
	
	//insert(l, 0);
	S.erase(l);
	
	return g(n-1, linw-l0, k);
	
}
int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin>>n>>k;
	//M[1][0]=1;
	M[1].pb(1);
	S.erase(20);
	while(N<n)
		N*=2;
	for (int i=0; i<n; i++)
	{
		W[i+N]=1;
		S.insert(i+1);
	}
	for (int i=N-1; i>0; i--)
	{
		W[i]=W[2*i]+W[2*i+1];
	}
	for (int i=2; i<=n; i++)
	{
		//cout<<i<<"\n";
		for (int j=0; j<M[i-1].size(); j++)
		{
			M[i].pb(M[i-1][j]);
		}
		int j=1;
		/*for (auto it : M[i])
		{
			cout<<it<<" ";
		}
		cout<<"\n";*/
		for (; M[i][j-1]<inf && M[i][j-1]!=0 && j<=i*(i-1)/2; j++)
		{
			if (j>=M[i].size())
				M[i].pb(0);
			M[i][j]+=M[i][j-1];
			M[i][j]-=(j-i>=0 /*&& j-i<M[i-1].size()*/ ? M[i-1][j-i] : 0);
		}
		/*for (auto it : M[i])
		{
			cout<<it<<" ";
		}
		cout<<"\n";*/
		while(M[i].size()>j)
			M[i].pop_back();
		if (M[i][j-1]>inf)
			M[i][j-1]=inf;
		/*for (auto it : M[i])
		{
			cout<<it<<" ";
		}
		cout<<"\n";*/
		/*for (int j=1; M[j-1]<inf && M[j-1]!=0; j++)
		{
			M[i][j]+=M[i][j-1];
		}
		for (int j=1; )*/
	}
	int ilezost=n*(n-1)/4;
	if ((n*(n-1))%4!=0 || f(n,n*(n-1)/4)<k)
	{
		cout<<"NIE";
		return 0;
	}
	cout<<"TAK\n";
	/*for (int i=0; i<n; i++)
	{
		auto it = nast[0];
		for (int j=0; f(n-i-1, ilezost-i+1)<k; it=nast[it])
		{
			k-=f(n-i-1, ilezost-i+1);
		}
		cout<<it<<" ";
		nast[poprz[it]]=nast[it];
		poprz[nast[it]]=poprz[it];
	}*/
	//return 0;
	g(n, ilezost, k);
	return 0;
}