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

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

    std::string result = "";
    for(int i = 0; i < n; i++)
    {
        std::string pos;
        std::cin >> pos;
        if(pos[0] == '5')
        {
            size_t n;
            if((n = result.find(pos)) != std::string::npos)
                if(result.find(pos,n + 1) != std::string::npos)
                   continue;
            result += pos; 
        }
        else if(result.find(pos) == std::string::npos)
            result += pos;
    }
    if(result.length() == 2*18)
        std::cout << "TAK";
    else
        std::cout << "NIE";
    return 0;
}