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
#include<algorithm>
//#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#define FOR(i,n) for(int i = 0;i<n;++i)
#define FORI(i,b,n) for(int i = b;i<n;++i)
#define FORD(i,n) for(int i = n;i>=0;--i)
#define ZERO 0.000001
#define MAX ((1<<31)-1)
#define qprintf debug && printf
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define ull long long int
using namespace std;
int debug=0;
#define dcout debug && cout
class F
{
	public:
		int n;
	int d;
	int h;
};

ostream& operator<<(ostream& os, const F r)
{
	os<<"["<<r.n<<","<<r.d<<","<<r.h<<"]";
	return os;
}
struct C
{
	bool operator()(F a, F b){
		return a.d<b.d;
	}
};
struct RC
{
	bool operator()(F a, F b){
		return a.h>b.h;
	}
};
int main(){
	ios_base::sync_with_stdio(0);
	int n;
	long long int life;
	cin>>n>>life;
	int iwin=0,iloose=0,idraw=0;
	F*win=new F[n];
	F*loose=new F[n];
	F*draw=new F[n];
	FOR(i,n){
		int d,h;
		cin>>d>>h;
		F*s = d<h? (win+(iwin++)) : (d>h? (loose+(iloose++)) : (draw+(idraw++)));
		s->n=i+1;
		s->d=d;
		s->h=h;
		dcout<<*s<<endl;
	}
	C c;
	RC rc;
	sort(win,win+iwin,c);
	sort(draw,draw+idraw,c);
	sort(loose,loose+iloose,rc);
	dcout<<"WINS:"<<endl;
	FOR(i,iwin){
		dcout<<win[i]<<endl;
		if(life<=win[i].d){
			cout<<"NIE"<<endl;
			return 0;
		}
		life+=-win[i].d+win[i].h;
	}
	dcout<<"DRAWS:"<<endl;
	FOR(i,idraw){
		dcout<<draw[i]<<endl;
		if(life<=draw[i].d){
			cout<<"NIE"<<endl;
			return 0;
		}
	}
	dcout<<"LOOSE:"<<endl;
	FOR(i,iloose){
		dcout<<loose[i]<<endl;
		if(life<=loose[i].d){
			cout<<"NIE"<<endl;
			return 0;
		}
		life+=-loose[i].d+loose[i].h;
	}
	cout<<"TAK"<<endl;
	FOR(i,iwin)cout<<win[i].n<<" ";
	FOR(i,idraw)cout<<draw[i].n<<" ";
	FOR(i,iloose)cout<<loose[i].n<<" ";
	cout<<endl;

	return 0;
}