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
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class boh {
	public static class S {
		public static class T {
			static T scan(InputStream in) {
				try (Scanner scanner = new Scanner(in)) {
					int n = scanner.nextInt();
					int z = scanner.nextInt();
					int[][] p = new int[n][];
					for (int i = 0; i < n; i++) {
						p[i] = new int[3];
						p[i][0] = scanner.nextInt();
						p[i][1] = scanner.nextInt();
						p[i][2] = i+1;
					}
					return new T(n, z, p);
				}
			}
			
			static int sign(int i) {
				if (i<0) return -1;
				if (i>0) return 1;
				return 0;
			}

			static int sign(int[] p) {
				return sign(p[1]-p[0]);
			}
			
			int n, z;
			int [][] p;
			
			boolean solvable;
			
			T(int _n, int _z, int[][] _p) {
				n = _n; z = _z; p = _p;
			}
			
			void solve() {
				Arrays.sort(p, new Comparator<int[]>() {
					@Override
					public int compare(int[] p1, int[] p2) {
						int s1 = sign(p1);
						int s2 = sign(p2);
						if (s1!=s2)	return s2-s1;
						if (s1>=0) return p1[0]-p2[0];
						return p2[0]-p1[0];
					}
				});
				long l = z;
				for (int i = 0; i < n; i++) {
					l -= p[i][0];
					if (l<=0) {
						solvable = false;
						return;
					}
					l += p[i][1];
				}
				solvable = true;
			}
			
			void printSolution(PrintStream out) {
				out.println(solvable?"TAK":"NIE");
				out.print(p[0][2]);
				for (int i = 1; i < n; i++) {
					out.print(' ');
					out.print(p[i][2]);
				}
				out.println();
			}
		}
		
		void main(InputStream in, PrintStream out) {
			T t = T.scan(in);
			t.solve();
			t.printSolution(out);
		}
	}

	public static void main(String[] args) {
		new S().main(System.in, System.out);
	}
}