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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int t;
    cin >> t;

    for (int x = 0; x < t; x++) {
        if (x != 0) cout << endl;
        int n;
        cin >> n;

            int maxA = 0;
            int minA = 1000001;
            int maxB = 0;
            int minB = 1000001;
//            long sumA = 0;
//            long sumB = 0;
//            long wsumA = 0;
//            long wsumB = 0;
            long s = 0;

            for (int i = 0; i < n; i++) {
                int l; cin >> l;
                int a; cin >> a;
                int b; cin >> b;
//                sumA += a;
//                sumB += b;
//                wsumA += l*a;
//                wsumB += l*b;
                s += l*b - l*a;
//                System.out.println("s: " + s);
                if (a < minA) minA = a;
                if (a > maxA) maxA = a;
                if (b < minB) minB = b;
                if (b > maxB) maxB = b;
//                l[i] = scanner.nextInt();
//                a[i] = scanner.nextInt();
//                b[i] = scanner.nextInt();
//                if (a[i] < minA) {
//                    minA = a[i];
//                }
//                if (a[i] > maxA) {
//                    maxA = a[i];
//                }
//                if (b[i] < minB) {
//                    minB = b[i];
//                }
//                if (b[i] > maxB) {
//                    maxB = b[i];
//                }
            }
//            System.out.println("minA: " + minA);
//            System.out.println("maxA: " + maxA);
//            System.out.println("minB: " + minB);
//            System.out.println("maxB: " + maxB);
            bool borders = maxB <= maxA && minB >= minA;
//            boolean energyEqual = wsumA == wsumB;
//            boolean tempEqual = sumA == sumB;
            bool energyEqual = s == 0;
            bool yes = borders && energyEqual;
            cout << (yes ? "TAK" : "NIE");
        }

}