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
76
#include <iostream>
#include <string>
using namespace std; 
  
int main() 
{ 
    // declaring list 
    int tablicaA[5];
    int tablicaB[5];  
    int tablicaC[5];
    
    tablicaA[0] = 1;
    tablicaA[1] = 1;
    tablicaA[2] = 1;
    tablicaA[3] = 1;
    tablicaA[4] = 2;
    
    tablicaB[0] = 1;
    tablicaB[1] = 1;
    tablicaB[2] = 1;
    tablicaB[3] = 1;
    tablicaB[4] = 2;
    
    tablicaC[0] = 1;
    tablicaC[1] = 1;
    tablicaC[2] = 1;
    tablicaC[3] = 1;
    tablicaC[4] = 2;
    
    
    int n;
    cin >>n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        int liczba;
        int abc = 0;
        for(char& c : s) {
            if (abc == 0) {
                liczba = c - '0';
                abc++;
            }
            else {
                if (c == 'A'){
                    tablicaA[liczba-1] = tablicaA[liczba-1] -1;
                }
                else if (c == 'B'){
                    tablicaB[liczba-1] = tablicaB[liczba-1] -1;            
                }
                else if (c == 'C'){
                    tablicaC[liczba-1] = tablicaC[liczba-1] -1;
                }
            }
        }
    }
    bool b = true;
    for (int i = 0; i < 5; i++) {
        if(tablicaA[i] > 0){
            b = false;
        }
        if(tablicaB[i] > 0){
            b = false;
        }
        if(tablicaC[i] > 0){
            b = false;
        }
    }
    if (b){
        std::cout << "TAK" << std::endl;
    }
    else{
        std::cout << "NIE" << std::endl;
    }
    
    return 0;
}