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<iostream>
#include<unordered_set>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;

    if (n < 18) {
        cout<<"NIE"<<endl;
        return 0;
    }

    unordered_set<int> A;
    unordered_set<int> B;
    unordered_set<int> C;

    string s;
    for (int i = 0; i < n; i++)
    {
        cin>>s;
        char division = s[1];
        char roundc = s[0];
        int round = roundc - '0';
        if (division == 'A') {
            if (round == 5) {
                if (A.count(51) == 0) {
                    A.insert(51);
                }
                else {
                    A.insert(52);
                }
            }
            else {
                A.insert(round);
            }
        }
        else if (division == 'B') {
            if (round == 5) {
                if (B.count(51) == 0) {
                    B.insert(51);
                }
                else {
                    B.insert(52);
                }
            }
            else {
                B.insert(round);
            }
        }
        else {
            if (round == 5) {
                if (C.count(51) == 0) {
                    C.insert(51);
                }
                else {
                    C.insert(52);
                }
            }
            else {
                C.insert(round);
            }
        }
    }

    if (A.size() == 6 && B.size() == 6 && C.size() == 6) {
        cout<<"TAK"<<endl;
    }
    else {
        cout<<"NIE"<<endl;
    }
    
    return 0;
}