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
#include <cstdio>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int tests, childrens, bitres = 0, realTemp = 0, reqTemp = 0;
    cin >> tests;
    int tmpBitres, tmpRealTemp, tmpReqTemp;
    int bajtoniatka[1000000];
    int resReal = 0, resReq = 0;
    while (tests-- > 0)
    {
        tmpRealTemp = 0;
        tmpReqTemp = 0;
        tmpBitres = 0;
        resReal = 0;
        resReq = 0;
        cin >> childrens;
        int all = childrens;
        int lowest1, lowest2;
        int biggest1, biggest2;
        while (childrens-- > 0)
        {
            cin >> tmpBitres >> tmpRealTemp >> tmpReqTemp;
            if (childrens + 1 == all)
            {
                lowest1 = tmpRealTemp;
                lowest2 = tmpReqTemp;
                biggest1 = tmpRealTemp;
                biggest2 = tmpReqTemp;
            }
            resReal += tmpBitres * tmpReqTemp;
            resReq += tmpBitres * tmpRealTemp;
            if (tmpRealTemp < lowest1)
                lowest1 = tmpRealTemp;
            if (tmpReqTemp < lowest2)
                lowest2 = tmpReqTemp;
            if (tmpRealTemp > biggest1)
                biggest1 = tmpRealTemp;
            if (tmpReqTemp > biggest2)
                biggest2 = tmpReqTemp;
            //bitres += tmpBitres;
            //realTemp += tmpRealTemp;
            //reqTemp += tmpReqTemp;
            //resReal = bitres*
        }

        //cout << resReq << " " << resReal << endl;
        if (biggest2 > biggest1 || lowest2 < lowest1 || resReq != resReal)
            cout << "NIE" << endl;
        else
            cout << "TAK" << endl;
    }
    return 0;
}