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

bool valid(string s){
    return s.size() == 2 && s[0] >= '1' && s[0] <= '5' && s[1] >= 'A' && s[1] <= 'C';
}

int main(){
    int n;
    cin>>n;
    unordered_map <string, int> m;

    for(int i=0 ; i<n ; i++){
        string s;
        cin>>s;
        if(valid(s)){
            if(m.find(s)!=m.end()) m[s]++;
            else m[s] = 1;
        }
    }

    bool r = true;

    for(char i='1' ; i<='5' ; i++){
        for(char c = 'A' ; c<='C' ; c++){
            string s = "AA";
            s[0] = i;
            s[1] = c;
            if(i=='5'){
                if(m[s] < 2){
                    r = false;
                    break;
                }
            }else{
                if(m[s] < 1){
                    r = false;
                    break;
                }
            }
        }
        if(!r) break;
    }

    cout<< (r ? "TAK" : "NIE");

    return 0;
}