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

using namespace std;

int t, n, l[100001], a[100001], b[100001], maksimuma, minimuma, maksimumb, minimumb;
long long wagaa, wagab, sredniaa, sredniab;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    for (int j = 0; j < t; ++j) {
        maksimuma = 0;
        minimuma = 1000001;
        maksimumb = 0;
        minimumb = 1000001;
        wagaa = 0;
        wagab = 0;
        cin >> n;
        for (int i = 1; i <= n; ++i) {
            cin >> l[i] >> a[i] >> b[i];
            maksimuma = max(maksimuma, a[i]);
            minimuma = min(minimuma, a[i]);
            maksimumb = max(maksimumb, b[i]);
            minimumb = min(minimumb, b[i]);
        }
        for (int i = 1; i <= n; ++i) {
            wagaa += a[i] * l[i];
            wagab += b[i] * l[i];
        }
        if (minimumb < minimuma || maksimumb > maksimuma || wagaa != wagab) {
            cout << "NIE" << endl;
        } else {
            cout << "TAK" << endl;
        }
    }
    return 0;

}