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

using namespace std;

void solve();
int index_of(const char number, const char division);
bool enough_problems(const vector<int>& problemset);

int main() {
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

void solve() {
    int problem_count;
    cin >> problem_count;
    vector<int> problemset(12);
    for(int p = 0; p < problem_count; p++)
    {
        char round_number;
        cin >> round_number;
        char division;
        cin >> division;
        problemset[index_of(round_number, division)]++;
    }
    if(enough_problems(problemset))
        cout << "TAK";
    else
        cout << "NIE";
    cout << endl;
}

int index_of(const char number, const char division) {
    return 3 * (static_cast<int>(number - '1')) + static_cast<int>(division - 'A');
}

bool enough_problems(const vector<int>& problemset) {
    for(char number = '1'; number <= '5'; number++)
    {
        for(char division = 'A'; division <= 'C'; division++)
        {
            int available_problems = problemset[index_of(number, division)];
            if((available_problems < 1) || (available_problems < 2 && number == '5'))
                return false;
        }
    }
    return true;
}