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
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <complex>
#include <sstream>
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<int,int> PII;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)
#define ALL(v) (v).begin(), (v).end()
 
#define pb push_back
#define mp make_pair
#define st first
#define nd second

struct Monster {
  int d;
  int a;
  int id;
  Monster(int _d, int _a, int _id): d(_d), a(_a), id(_id) {}
};

bool cmp(Monster m1, Monster m2) {
  if ((m1.a > m1.d) != (m2.a > m2.d)) return m1.a > m1.d;
  if (m1.a > m1.d) return m1.d < m2.d;
  else return m1.a > m2.a;
}

void scase() {
  int N;
  LL Z;
  scanf("%d%lld",&N,&Z);
  vector<Monster> V;

  REP(i,N) {
    int d,a;
    scanf("%d%d",&d,&a);
    V.push_back(Monster(d,a,i+1));
  }
  sort(V.begin(), V.end(), cmp);
  REP(i,N) {
    if (Z <= V[i].d) {
      printf("NIE\n");
      return;
    }
    Z = Z - V[i].d + V[i].a;
  }
  printf("TAK\n");
  REP(i,N) printf("%d ", V[i].id);
  printf("\n");
}

int main() {
  scase();
}