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
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll a[5], b[5], c[5];

bool check() {
    for (int i = 0; i < 4; ++i) {
        if (a[i] < 1 || b[i] < 1 || c[i] < 1) return false;
    }

    return (a[4] >= 2 && b[4] >= 2 && c[4] >= 2);
}

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

    char num, letter;
    for (int i = 0; i < n; ++i) {
        cin >> num >> letter;
        ll id = num - '1';
        switch (letter) {
            case 'A':
                a[id]++;
                break;
            case 'B':
                b[id]++;
                break;
            case 'C':
                c[id]++;
                break;
        }
    }

    if (check()) cout << "TAK";
    else cout << "NIE";
}