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 <stdio.h>
int n;
char c;
unsigned long long int w1,w2,w3,w4,w5,w6;
unsigned long long int p1=97,p2=1006969,p3=83,p4=1999969,p5=100000193,p6=100000213;
unsigned long long int k1=1,k3=1,k5=1;
int main(){
    scanf("%d\n",&n);
    while(scanf("%c",&c)==1 && c>='a'){
        w1=(w1*p1+c)%p2;
        w2=(w2+k1*c)%p2;
        k1=(k1*p1)%p2;
        
        w3=(w3*p3+c)%p4;
        w4=(w4+k3*c)%p4;
        k3=(k3*p3)%p4;
        
        w5=(w5*p5+c)%p6;
        w6=(w6+k5*c)%p6;
        k5=(k5*p5)%p6;
    }
    if(w1==w2 && w3==w4 && w5==w6)
        printf("TAK");
    else
        printf("NIE");
}