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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define scanf(...) scanf(__VA_ARGS__)?:0
#define e1 first
#define e2 second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,m,mint=1000000,maxt=0,p[101],k[101],c[101],s[101],w[1000001];
int main()
{
	scanf("%d%d",&n,&m);
	FOR(i,1,n) scanf("%d%d%d",&p[i],&k[i],&c[i]),s[i]=i,mint=min(p[i],mint),maxt=max(k[i],maxt);
	sort(s+1,s+n+1,[](int a,int b){return k[a]<k[b];});
	FOR(t,mint,maxt)
	{
		FOR(i,1,n)
		{
			if (t==k[s[i]] && c[s[i]]) puts("NIE"),exit(0);
			if (t<p[s[i]] || t>=k[s[i]] || c[s[i]]==0) continue;
			if (k[s[i]]-t==c[s[i]]) w[t]++;
			if (w[t]>m) puts("NIE"),exit(0);
		}
		FOR(i,1,n)
		{
			if (t<p[s[i]] || t>=k[s[i]] || c[s[i]]==0) continue;
			if (k[s[i]]-t==c[s[i]]) c[s[i]]--;
			else if (w[t]<m) w[t]++,c[s[i]]--;
		}
	}
	puts("TAK");
}