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
#include <bits/stdc++.h>
using namespace std;
const int MM=3;
const int pod=997; //ten numer to klopoty
long long H[MM],h[MM],P[MM];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    P[0]=1000000009;
    P[1]=1000000007;
    P[2]=1000696969;
    long long p[MM];
    for(int i=0;i<MM;i++)   p[i]=1;
    char a;
    cin>>n;
    while(cin>>a)
    {
        for(int i=0;i<MM;i++)
        {
            H[i]*=pod;
            H[i]%=P[i];
            H[i]+=(int)(a-'a'+1);
            if(H[i]>=P[i])  H[i]-=P[i];
            h[i]+=(long long)(a-'a'+1)*p[i];
            h[i]%=P[i];
            p[i]*=pod;
            p[i]%=P[i];
        }
    }
    bool x=true;
    for(int i=0;i<MM;i++)   if(H[i]!=h[i])  x=false;
    cout<<(x?"TAK":"NIE");
    return 0;
}