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
#include <bits/stdc++.h>
using namespace std;
#define int long long
int a,p1=30,p2=27,pot1=1,pot2=1,hw1,hw2,hy1,hy2;
int m1=1059811231,m2=1059811777;
char c;
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>a;
        while(cin>>c)
        {
            c-='a'-1;
            hw1=(hw1*p1+c)%m1;
            hy1=(hy1+c*pot1)%m1;
            hw2=(hw2*p2+c)%m2;
            hy2=(hy2+c*pot2)%m2;
            pot1=(pot1*p1)%m1;
            pot2=(pot2*p2)%m2;
        }
       if(hw1==hy1 && hw2==hy2 )
         cout<<"TAK"<<endl;
        else cout<<"NIE"<<endl;
}