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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;


public class boh {
	
	public static class Monster implements Comparable<Monster> {
		int num;
		int d;
		int a;
		int pos;
		
		public Monster(int num, int d, int a) {
			super();
			this.num = num;
			this.d = d;
			this.a = a;
			this.pos = (d < a ? 3 : (d == a ? 2 : 1));
		}
		
		@Override
		public int compareTo(Monster m) {
			if(pos != m.pos) {
				return m.pos - pos;
			} else {
				if(pos == 3) {
					return d - m.d;
				} else if(pos == 2) {
					return 0;
				} else {
					return m.a - a;
				}
			}
		}
		
		public String toString() {
			return "{" + num + "}";
		}
	}
	
    public static void main(String[] args) throws IOException {
    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer tokenizer;
    	
    	tokenizer = new StringTokenizer(reader.readLine());
    	int n = Integer.parseInt(tokenizer.nextToken());
    	int z = Integer.parseInt(tokenizer.nextToken());
    	
    	Monster[] monsters = new Monster[n];
    	for(int i = 0; i < n; i++) {
    		tokenizer = new StringTokenizer(reader.readLine());
        	int d = Integer.parseInt(tokenizer.nextToken());
        	int a = Integer.parseInt(tokenizer.nextToken());
        	monsters[i] = new Monster(i+1, d, a);  
    	}
    	
    	Arrays.sort(monsters);
    	
    	int zTmp = z;
    	boolean possible = true;
    	for(int i = 0; i < n; i++) {
    		zTmp -= monsters[i].d;
    		if(zTmp <= 0) {
    			possible = false;
    		}
    		zTmp += monsters[i].a;
    	}
    	
    	if(possible) {// || true) {
    		System.out.println("TAK");
    		System.out.print(monsters[0].num);
    		for(int i = 1; i < n; i++) {
    			System.out.print(" " + monsters[i].num);
    		}
    		System.out.println();
    	} else {
    		System.out.println("NIE");
    	}
    }
}