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
#include <iostream>
#include <set>
#include <cmath>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>

#define MP make_pair
#define ST first
#define ND second
#define PII pair<int,int>
#define PPIII pair<PII,int>
#define PIB pair<int,bool>
#define PPIII pair<PII,int>
#define PB push_back
#define VI vector<int>
#define VLI vector<long long>
#define VVLI vector<VLI>
#define VB vector<bool>
#define VPII vector<PII>
#define VPPIII vector<PPIII>
#define VPIB vector<PIB>
#define PB push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;

int tab[4][100000];

bool cmp(PPIII a, PPIII b)
{
	if((double)a.ST.ST/((double)(a.ST.ST-a.ST.ND)) > (double)b.ST.ST/((double)(b.ST.ST-b.ST.ND)))
		return false;
	return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n, hp;
	cin>>n>>hp;
	VPPIII d, z;
	VI w;
	for(int i=0;i<n;i++)
	{
		int a, b;
		cin>>a>>b;
		if(a>b)
			z.PB(MP(MP(a, b), i+1));
		else
			d.PB(MP(MP(a, b), i+1));
	}

	sort(d.begin(), d.end());
	for(int i=0;i<d.size();i++)
	{
		if(d[i].ST.ST>=hp)
		{
			cout<<"NIE"<<endl;
			return 0;
		}
		w.PB(d[i].ND);
		hp+=d[i].ST.ND-d[i].ST.ST;
	}

	bool dasie=true;

	sort(z.begin(), z.end(), cmp);

	for(int i=z.size()-1;i>=0;i--)
	{
		if(z[i].ST.ST>=hp)
		{
			dasie=false;
		}
		w.PB(z[i].ND);
		hp+=z[i].ST.ND-z[i].ST.ST;
	}

	if(!dasie)
	{
		sort(z.begin(), z.end());

		for(int i=z.size()-1;i>=0;i--)
		{
			if(z[i].ST.ST>=hp)
			{
				cout<<"NIE"<<endl;
				return 0;

			}
			w.PB(z[i].ND);
			hp+=z[i].ST.ND-z[i].ST.ST;
		}

	}

	cout<<"TAK"<<endl;
	for(int i=0;i<n;i++)
	{
		cout<<w[i];
		if(i<n-1)
			cout<<" ";
		else
			cout<<endl;
	}



	return 0;
}