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

int main(void)
{
    std::uint32_t n;
    std::cin >> n;
    if (n < 18) {
        std::cout << "NIE\n";
        return 0;
    }

    std::multiset<std::string> tasks;
    for (int i = 1; i < 6; ++i) {
        tasks.emplace(std::to_string(i) + "A");
        tasks.emplace(std::to_string(i) + "B");
        tasks.emplace(std::to_string(i) + "C");
    }

    tasks.emplace(std::to_string(5) + "A");
    tasks.emplace(std::to_string(5) + "B");
    tasks.emplace(std::to_string(5) + "C");

    while (n--) {
        std::string task;
        std::cin >> task;
        auto it = tasks.find(task);
        if (it != tasks.end()) {
            tasks.erase(it);
        }
    }

    if (tasks.size() == 0) {
        std::cout << "TAK\n";
    }
    else {
        std::cout << "NIE\n";
    }

    return 0;
}