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
#include<bits/stdc++.h>
using namespace std;

const long long MOD1=1e9+7;
const long long MOD2=1e9+696969;
const long long MOD3=1e9+7;
const long long base=29;

int main()
{
    long long l1=0,l2=0,l3=0,p1=0,p2=0,p3=0;
    long long b1=1,b2=1,b3=1;
    long long akt;
    int d;
    scanf ("%d", &d);
    getchar();
    char c=getchar();
    while (c>='a'&&c<='z')
    {
        akt=(long long)(c)-96;

        l1*=base;
        l1+=akt;
        l1%=MOD1;
        p1+=b1*akt;
        p1%=MOD1;
        b1*=base;
        b1%=MOD1;

        l2*=base;
        l2+=akt;
        l2%=MOD2;
        p2+=b2*akt;
        p2%=MOD2;
        b2*=base;
        b2%=MOD2;

        l3*=base;
        l3+=akt;
        l3%=MOD3;
        p3+=b3*akt;
        p3%=MOD3;
        b3*=base;
        b3%=MOD3;

        c=getchar();
    }
    if (l1==p1&&l2==p2&&l3==p3)
        printf ("TAK");
    else
        printf ("NIE");
    return 0;
}