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

using namespace std;

int main()
{
    int n;
    cin >> n;

    if (n < 18) {
        cout << "NIE";
    }
    else {
        bool A[4];
        bool B[4];
        bool C[4];

        for (int i = 0; i < 4; i++) {
            A[i] = false;
            B[i] = false;
            C[i] = false;
        }

        int A5Counter = 0;
        int B5Counter = 0;
        int C5Counter = 0;

        for (int i = 0; i < n; i++) {
            string set;
            cin >> set;

            int number = set[0] - '0';

            if (set[1] == 'A' && number != 5) {
                A[number - 1] = true;
            } else if (set[1] == 'B' && number != 5) {
                B[number - 1] = true;
            } else if (set[1] == 'C' && number != 5) {
                C[number - 1] = true;
            } else if (set[1] == 'A' && number == 5) {
                A5Counter++;
            } else if (set[1] == 'B' && number == 5) {
                B5Counter++;
            } else if (set[1] == 'C' && number == 5) {
                C5Counter++;
            }
        }

        bool allTasks = true; // flaga

        if (A5Counter < 2 || B5Counter < 2 || C5Counter < 2) {
            allTasks = false;
        }
        else {
            for (int i = 0; i < 4; i++) {
                if (!(A[i]) || !(B[i]) || !(C[i])) {
                    allTasks = false;
                }
            }
        } 

        if (allTasks) {
            cout << "TAK";
        }
        else {
            cout << "NIE";
        }
    }
}