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
#include <iostream>
#include <vector>
#include <set>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> A(5, 0);
    vector<int> B(5, 0);
    vector<int> C(5, 0);
    int stillNeeded = 15;
    for (int i = 0; i < n; i++)
    {
        string question;
        cin >> question;
        int numOfQst = question[0] - '0';
        if (question[1] == 'A')
        {
            A[numOfQst] += 1;
            if ((numOfQst <= 4 and A[numOfQst] == 1) or (numOfQst == 5 and A[numOfQst] == 2))
                stillNeeded--;
        }
        else if (question[1] == 'B')
        {
            B[numOfQst] += 1;
            if ((numOfQst <= 4 and B[numOfQst] == 1) or (numOfQst == 5 and B[numOfQst] == 2))
                stillNeeded--;
        }
        else
        {
            C[numOfQst] += 1;
            if ((numOfQst <= 4 and C[numOfQst] == 1) or (numOfQst == 5 and C[numOfQst] == 2))
                stillNeeded--;
        }
    }
    cout << (stillNeeded == 0 ? "TAK" : "NIE") << endl;
    return 0;
}