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
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20);
#define inf 1000000007
#define INF 1000000000000000000LL
#define mod 1000000007
#define VI vector<int>
#define VPI vector < pair<int,int> >
#define PII pair<int, int>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define REP(x, y) for(int x = 0; x < (y); ++x)
#define FOR(x, y, z) for(int x = y; x <= (z); ++x)
#define FORR(x, y, z) for(int x = y; x >= (z); --x)
using namespace std;
#define N 10007

int pocz[N]; // zeby w czasie stalym
int kon[N]; // zeby w czasie stalym
int iledozrobienia[N]; // ile ogolnie

VPI poczatek,koniec,s; // parami
VI g;
int n,m,od,to,ile;

int start=inf,finish=0;


int main()
{
	boost

	cin >> n >> m;

	FOR(i,1,n)
	{
		cin >> od >> to >> ile;

		start=min(start,od);
		finish=max(finish,to);

		poczatek.pb(mp(od,i));
		koniec.pb(mp(to,i));

		pocz[i]=od;
		kon[i]=to;
		iledozrobienia[i]=ile;
	}

	sort(poczatek.begin(),poczatek.end());
	sort(koniec.begin(),koniec.end());

	int pom1=0; 

	//cout << endl;

	FOR(i,start,finish)
	{
		while(poczatek[pom1].st<=i && pom1<poczatek.size())
		{
			s.pb(mp ( kon[poczatek[pom1].nd]-pocz[poczatek[pom1].nd]-iledozrobienia[poczatek[pom1].nd] ,poczatek[pom1].nd) );
			pom1++;
		}

		sort(s.begin(),s.end());
/*
		REP(j,s.size())
		{
			cout << s[j].st << " " << s[j].nd << endl;
		}
		cout << endl;
*/
		REP(j,s.size())
		{
			if (j<m)
			{
				iledozrobienia[s[j].nd]--;
				if (iledozrobienia[s[j].nd]==0)
				{
					g.pb(s[j].nd);
					continue;
				}
			}
			else
			{
				s[j].st--;
				if (s[j].st<0)
				{
					cout <<"NIE" << endl;
					return 0;
				}
			}
		}

		REP(j,g.size())
		{
			REP(ij,s.size())
			{
				if (s[ij].nd==g[j])
				{
					s.erase(s.begin()+ij);
					break;
				}
			}
		}
/*
		REP(j,s.size())
		{
			cout << s[j].st << " " << s[j].nd << endl;
		}
		cout << endl;
*/		
	}

	cout << "TAK" << endl;

    
    return 0;
}