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
#include <iostream>
#include <stdio.h>

using namespace std;

int n,m,l,a,b;
long long curr,needed;
int biggest_n,smallest_n,biggest_c,smallest_c;

int main()
{
    scanf("%d",&n);

    for(int i=0;i<n;i++){
        scanf("%d",&m);
        curr=0;
        needed=0;
        biggest_n=0;
        biggest_c=0;
        smallest_n=1000001;
        smallest_c=1000001;
        for(int i=0;i<m;i++){
            scanf("%d%d%d",&l,&a,&b);
            if(biggest_c<a) biggest_c=a;
            if(biggest_n<b) biggest_n=b;
            if(smallest_c>a) smallest_c=a;
            if(smallest_n>b) smallest_n=b;
            curr+=a*l;
            needed+=b*l;
        }
        if(curr==needed&&smallest_n>=smallest_c&&biggest_n<=biggest_c) printf("TAK\n");
        else printf("NIE\n");
    }
    return 0;
}