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
#include <iostream>

using namespace std;

int main()
{
    long long int t, n, l, a, b, mina, maxa, minb, maxb, sa, sb;
    cin >> t;
    for (long int i=0; i<t; i++)
    {
        cin >> n;
        mina=1000000;maxa=0;
        minb=1000000;maxb=0;
        sa=0; sb=0;
        for (long int j=0; j<n; j++)
        {
            cin >> l >> a >> b;
            if (a<mina) mina=a;
            if (a>maxa) maxa=a;
            if (b<minb) minb=b;
            if (b>maxb) maxb=b;
            sa+=l*a;
            sb+=l*b;
        }
        if (sa==sb && minb>=mina && maxb<=maxa)
            cout << "TAK\n";
        else
            cout << "NIE\n";
    }
    return 0;
}