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
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <map> 
#include <string>
#include <vector>  
#include <iostream> 
#include <sstream> 
#include <queue>
#include <algorithm>

using namespace std;
 
#define ll long long
#define PB 		push_back
#define FOR(a,start,end) 	for(ll a=ll(start); a<ll(end); a++)
#define INF 		INT_MAX
#define SORT(a) 	sort(a.begin(),a.end()) 
#define CL(a,x) 		memset(a,x,sizeof(a))
#define REP(a,x)	for(ll a=0;a<x;a++)
#define REP1(a,x)	for(ll a=1;a<=x;a++)
#define MP 		make_pair

 
 
typedef vector<int>     vi;
typedef pair<int,int>     pii; 
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vector<int> > vvi;
typedef vector<vector<string> > vvs;
typedef vector<pair<string,string> > vss;
typedef pair<string,string> pss; 
typedef pair<int,pii> ppii;
typedef vector<ppii> vppii;
typedef vector<vector<pii> > vvii;
typedef vector<vvi> vvvi;


ppii px;
vppii vc,vc2;
int i0,i,j,k,n,a,a2,k1,k2;
ll z,c,d,t,z1;
ll m,b; 
ll cas,g,ng,p,np;
ll w1,w2,h1,h2;
ll wmin,wmax,hmin,hmax;
vi vk,vk2; 
vii vp,vd;
vvi vvk,vvp;	
pii p1,p2,p0; 
ll ta[100010];


int main() {  
//	freopen( "c:\\wojtek\\uva\\pa\\debug\\t1.in", "rt", stdin);  
	//	ll czas=clock();
	//pi=2*acos(0.0);
	 
	//scanf("%ld",&t);

	cin>>n>>z;
	vp.clear();
	vd.clear(); 
	
	vk.clear();
	vc.clear();
	CL(ta,0);
	for(i=0;i<n;i++){
		cin>>a>>b;
		vp.push_back(MP(a,b));
		if(b>=a){
			vd.push_back(MP(a,i));
		} 
		else {
			vc.push_back(MP(a,MP(b-a,i)));
			
		}
	}
	SORT(vd);
	SORT(vc);
	
	for(i=0;i<vd.size();i++){
		if(z>vd[i].first){
			z+=(ll)vp[vd[i].second].second-(ll)vp[vd[i].second].first;
			vk.push_back(vd[i].second);
			ta[vd[i].second]=1;
		}
		else {
			z=-1;
			break;
		}
	}
	
	if(z>0){
		vc2.clear();
		z1=z;
		for(i=vc.size()-1;i>=0;i--){
			if(z1-(ll)vc[i].first>0)
				z1+=(ll)vc[i].second.first;
			else {
				vc2.push_back(vc[i]);
				ta[vc[i].second.second]=2;
				z1+=(ll)vc[i].second.first;
			}
		}
		//if(vc2.size()>0){
			vk2.clear();
			j=0;
			z1=z;
			for(i=vc.size()-1;i>=0;i--){
				if(ta[vc[i].second.second]==0){
					if(j<vc2.size()){
						if((z1-(ll)vc[i].first>0)&&(z1+(ll)vc[i].second.first-(ll)vc2[j].first>0)){
							vk2.push_back(vc[i].second.second);
							z1+=(ll)vc[i].second.first;
						}
						else {
							while((j<vc2.size())&&(z1-(ll)vc2[j].first>0)){
								vk2.push_back(vc2[j].second.second);

								z1+=(ll)vc2[j].second.first;
								j++;
							}
							if(z1-vc[i].first>0){
								vk2.push_back(vc[i].second.second);
								z1+=(ll)vc[i].second.first;
							}
							else {
								z1=-1;
								break;
							}
						}

					}
					else {
						if(z1-vc[i].first>0){
							vk2.push_back(vc[i].second.second);
							z1+=(ll)vc[i].second.first;
						}
						else {
							z1=-1;
							break;
						}
					}

				}
			}
			z=z1;
			if(z>0){
				for(i=0;i<vk2.size();i++)
					vk.push_back(vk2[i]);
			}
		//}
		
	}
	if(z<=0)
		cout<<"NIE"<<endl;
	else {
		cout<<"TAK"<<endl;
		for(i=0;i<vk.size()-1;i++){
			cout<<vk[i]+1<<" ";
		}
		cout<<vk[i]+1<<endl;
	}

	

	//czas = clock() - czas;
	//printf("%lf\n",double(czas)/CLOCKS_PER_SEC);					

			
	return 0;
	 
}