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
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>

using namespace std;

#define N 100000

long long L[N];
long long A[N];
long long B[N];

int main() {
  long long t;

  scanf("%lld", &t);

  for (long long i = 0; i < t; i++) {
    long long n;
    long long sumA = 0;
    long long sumB = 0;
    long long sumL = 0;
    long long minA = INT_MAX;
    long long minB = INT_MAX;
    long long maxA = INT_MIN;
    long long maxB = INT_MIN;

    scanf("%lld", &n);
    for (long long j = 0; j < n; j++) {
      scanf("%lld %lld %lld", &(L[j]), &(A[j]), &(B[j]));
      sumA += L[j] * A[j];
      sumB += L[j] * B[j];
      sumL += L[j];
      minA = min(minA, A[j]);
      minB = min(minB, B[j]);
      maxA = max(maxA, A[j]);
      maxB = max(maxB, B[j]);
    }

    long long devA = 0;
    long long devB = 0;

    for (long long j = 0; j < n; j++) {
      devA += abs(A[i] * L[i] - sumA);
      devB += abs(B[i] * L[i] - sumB);
    }

    if (sumA != sumB || minB < minA || maxB > maxA || devB > devA) {
      printf("NIE\n");

    }
    else {
      printf("TAK\n");
    }
  }
  return 0;
}

/*
5
2
2 1 4
2 5 2
2
1 4 3
1 5 4
2
1 5 7
1 7 5
2
1 4 1
1 2 5
3
2 6 4
1 2 3
3 4 5
*/