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
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int q;

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cin >> q;
    for(int i = 0; i < q; i++){
        int n;
        cin >> n;
        ll sum1 = 0, sum2 = 0;
        ll mn1 = INT_MAX, mx1 = INT_MIN;
        ll mn2 = INT_MAX, mx2 = INT_MIN;
        for(int j = 0; j < n; j++){
            ll v, t, w;
            cin >> v >> t >> w;
            sum1 += (v * t);
            sum2 += (v * w);
            mn1 = min(mn1, t);
            mx1 = max(mx1, t);
            mn2 = min(mn2, w);
            mx2 = max(mx2, w);
        }
        if(sum1 == sum2 && mn1 <= mn2 && mx2 <= mx1) cout << "TAK\n";
        else cout << "NIE\n";
    }
    return 0;
}