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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

#define FOR(i,n) for(int i=0;i<n;++i)
#define FORB(i,b,n) for(int i=b;i<n;++i)
#define REV(i,n) for(int i=n;i>=0;--i)
#define FOREACH(T, it, v) for(T::iterator it = v.begin(); it !=v.end(); ++it)
#define print(STRING,INT) printf("%s= %d\n", STRING, INT)
#define scan(INT) scanf("%d", &INT)


typedef unsigned int u32;
const int INF = (0u - 11)/2;

typedef long long ll;
typedef set<int> SI;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef set<long long> SL;
typedef map<int, int> MII;
typedef multimap<int, int> MMII;


int DEBUG_ = 1;



void log(char* S, long long a)
{
    if(DEBUG_)
    {
        printf("%s= %I64d\n", S, a);
    }
}


struct A
{
	int a;
	int b;
	int index;
	A(int _a, int _b, int _index) : a(_a), b(_b), index(_index) {}
};

bool comper(A a, A b)
{
	if(a.a != b.a) return a.a < b.a;
	if(a.b != b.b) return a.b < b.b;
	return a.index < b.index;
}

int main()
{	
	vector<A> A1, A2;
	int n, z;
	scan(n);
	scan(z);
	int a, b;
	ll max = z;
	VI V;
	FOR(i,n)
	{
		scan(a);scan(b);
		if(a>b)
		{
			A2.push_back(A(b,a,i));
		}
		else
		{
			A1.push_back(A(a,b,i));

		}
	}
	sort(A2.begin(), A2.end(), comper);
	sort(A1.begin(), A1.end(), comper);
	for(vector<A>::iterator it = A1.begin(); it != A1.end(); it++)
	{
		if(it->a < max)
		{
			max += it->b - it->a;
			V.push_back(it->index);
		}
		else
		{
			cout << "NIE" << endl;
			return 0;
		}
	}
	//cout << max << endl;
	for(vector<A>::reverse_iterator it = A2.rbegin(); it != A2.rend(); it++)
	{
		if(it->b < max)
		{
			max -= it->b - it->a;
		}
		else
		{
			cout << "NIE" << endl;
			return 0;
		}
		V.push_back(it->index);
	}
	cout << "TAK" << endl;
	FOR(i, n)
	{
		printf("%d ", V[i]+1);
	}
	cout << endl;
	return 0;
}