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
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>

using namespace std;

const int64_t oo = INT64_MAX / 3;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    size_t T;
    cin >> T;
    while(T --> 0)
    {
        size_t n;
        cin >> n;

        int64_t E1 = 0, E2 = 0, L = 0,
                Tmin1 = +oo, Tmin2 = +oo, Tmax1 = -oo, Tmax2 = -oo;
        double D1 = 0, D2 = 0;
        vector<int64_t> l(n), a(n), b(n);
        for(size_t i = 0; i < n; i++)
        {
            cin >> l[i] >> a[i] >> b[i];
            L += l[i];
            E1 += l[i] * a[i];
            E2 += l[i] * b[i];

            Tmin1 = min(Tmin1, a[i]);
            Tmin2 = min(Tmin2, b[i]);
            Tmax1 = max(Tmax1, a[i]);
            Tmax2 = max(Tmax2, b[i]);
        }

        for(size_t i = 0; i < n; i++)
        {
            auto d1 = abs((a[i] - (double)E1/L)), d2 = abs((b[i] - (double)E2/L));
            D1 += l[i] * d1;
            D2 += l[i] * d2;
        }

        bool ok = E1 == E2 and Tmin1 <= Tmin2 and Tmax2 <= Tmax1;

        if(D1 < D2)
            ok = false;
        cout << (ok ? "TAK\n" : "NIE\n");
    }
}