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
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i,n) for(int i=0;i<n;++i)
#define REPD(i,n) for(int i=n;i>-1;--i)
#define FOR(i,j,k) for(int i=j;i<k;++i)
#define PB push_back
#define LL long long
#define MAX_S 101
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define INF 1000000001


int main(){
	cin.sync_with_stdio(false);
	
	int n;
	LL z; 
    cin>>n>>z;
	
	vector<pair<LL,LL> > rs;
	vector<pair<LL,LL> > d(n);
    

    vector<int> ret;
    LL minZ = -1;
   
	REP(i,n) 
	{
		 long long x,y; cin>>x>>y; 
		 d[i] = MP(x,y);
		 if(y-x>0) {z+=y-x; ret.PB(i+1);}
		 else if(y-x==0) 
		 {
				ret.PB(i+1);
				minZ = max(minZ,x+1);
		 }
		 else rs.PB(MP(x,i));
	}
	
	if(minZ>z) { cout<<"NIE"<<endl; return 0; }
	
	sort(ALL(rs));

	REPD(i,rs.size()-1) {
		 int idx = rs[i].second;		 
 		 z-=d[idx].first;
 		 if(z<1) { cout<<"NIE"<<endl; return 0; 	}
 	 	 z+=d[idx].second;
 	 	 ret.PB(idx+1);
	}

	cout<<"TAK"<<endl;
	REP(i,ret.size()) cout<<ret[i]<<" ";cout<<endl;

return 0;
}