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
71
72
// Karol Kosinski 2018
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
//#define DEBUG(x...) printf(x)
#define DEBUG(x...)
using namespace std;
typedef unsigned long long LL;

//const LL Prime[] = {99194853094756369LL};
const LL Prime[] = {99194853094755497LL, 99194853094756369LL};
const int MX = sizeof(Prime) / sizeof(LL);
const int D = 26;
const int CX = 20;
LL SumA[MX], SumB[MX], Pow[MX];

//bool is_prime(LL x)
//{
//    if(x < 2) return false;
//    if(x < 4) return true;
//    if(x % 2 == 0 or x % 3 == 0) return false;
//    for(LL i=5; i*i<=x; i+=6)
//    {
//        if(x % i == 0 or x % (i + 2) == 0) return false;
//    }
//    return true;
//}

bool check_sums()
{
    FOR(i,0,MX)
    {
        DEBUG("(%d)  %llu   %llu\n", i, SumA[i], SumB[i]);
        if(SumA[i] != SumB[i]) return false;
    }
    return true;
}

void count(LL x)
{
    FOR(i,0,MX)
    {
        SumA[i] = (SumA[i] * D + x) % Prime[i];
        SumB[i] = (SumB[i] + x * Pow[i]) % Prime[i];
        Pow[i] = (Pow[i] * D) % Prime[i];
    }
}

int main()
{
    //LL a = 99194853094755497LL, b = 1000;
    //for(LL i=a; i<a+b; ++i)
    //{
    //    if(is_prime(i)) printf("%llu\n", i);
    //}
    char cc[CX + 1];
    FOR(i,0,MX) Pow[i] = 1;
    scanf("%*d");
    while(scanf("%20s", cc) == 1)
    {
        DEBUG("%c", cc[0]);
        count(cc[0] - 'a');
        FOR(i,1,CX)
        {
            if(cc[i] == '\0') break;
            DEBUG("%c", cc[i]);
            count(cc[i] - 'a');
        }
    }
    DEBUG("\n");
    printf(check_sums() ? "TAK\n" : "NIE\n");
    return 0;
}