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
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;
const int N = 100000;

pair<int, int> tab[N];
int order[N];

bool compare1(int a, int b) {
  return tab[a].first < tab[b].first;
}

bool compare2(int a, int b) {
  return tab[a].second > tab[b].second;
}

bool compare(int a, int b) {
  int da = tab[a].second - tab[a].first;
  int db = tab[b].second - tab[b].first;
  if (da >= 0 && db >= 0) return compare1(a, b);
  if (da < 0 && db < 0) return compare2(a, b);
  return da > db;
}

int main() {
  int n;
  long long z;
  scanf("%d%lld", &n, &z);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &tab[i].first, &tab[i].second);
    order[i] = i;
  }
  sort(order, order + n, compare);
  for (int i = 0; i < n; ++i) {
    z -= tab[order[i]].first;
    if (z <= 0) break;
    z += tab[order[i]].second;
  }
  if (z <= 0) {
    printf("NIE\n");
  } else {
    printf("TAK\n");
    for (int i = 0; i < n; ++i) printf("%d ", order[i] + 1);
    printf("\n");
  }
  return 0;
}