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>

using namespace std;

const int M = (int)(1e9+696969);const int M2 = (int)(1223422313);

int main()
{
    int z;
    long long H=0;
    long long R=0;
    const long long p=29;
    long long pc=1;
    long long H2=0;
    long long R2=0;
    const long long p2=37;
    long long pc2=1;
    scanf("%d ",&z);
    char input;
    while(true)
    {
        input=getchar();
        if(input<97)
        {

            break;
        }
        H=H+(pc*((int)input-96));
        H2=H2+(pc2*((int)input-96));
        H%=M;
       H2%=M2;
        R=R*p+(int)input-96;
        R2=R2*p2+(int)input-96;
        R%=M;
        R2%=M2;
        pc=(pc*p)%M;
        pc2=(pc2*p2)%M2;


    }
    if(H==R && H2==R2)
    {
        printf("TAK");
    }
    else
    {
        printf("NIE");
    }

}