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
#include<cstdio>
typedef long long LL;
const LL n[4]={362,546961,3020,65563},
d[4]={197999881,197999881,198000259,198000259};
LL p[4]={1,1,1,1},s[4]={};
int main()
{
    scanf("%*d\n");
    char c;
    int i;
    while(scanf(" %c",&c)!=EOF)
    {
      //  printf("%d ",c);
        for(i=0;i<4;++i)
            s[i]=(s[i]+c*p[i])%d[i],p[i]=p[i]*n[i]%d[i];
    }
    s[0]=s[0]*p[1]%d[1]*n[0]%d[1];
    s[2]=s[2]*p[3]%d[3]*n[2]%d[3];
    //printf("\n%lld %lld %lld %lld\n",s[0],s[1],s[2],s[3]);
    if(s[0]==s[1] && s[2]==s[3])
        printf("TAK");
    else
        printf("NIE");
    return 0;
}