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
#include<stdio.h>
using namespace std;
typedef long long ll;
const ll p1 = 137, p2 = 2137, mod1 = 1000012361, mod2 = 1250000027;

ll hashleft1 = 0, hashright1 = 0;
ll hashleft2 = 0, hashright2 = 0;

int main(){
    register char b;
    int n;
    scanf("%d", &n);
    ll dod1 = 1;
    ll dod2 = 1;
    while((b = getchar_unlocked())!= EOF){
        if(b < 'a' or b > 'z')continue;
        hashleft1 = (hashleft1*p1+(ll)b)%mod1;
        hashleft2 = (hashleft2*p2+(ll)b)%mod2;
        hashright1 = (hashright1+(ll)b*dod1)%mod1;
        hashright2 = (hashright2+(ll)b*dod2)%mod2;
        dod1 = (dod1*p1)%mod1;
        dod2 = (dod2*p2)%mod2;
    }
    if(hashleft1 == hashright1 and hashleft2 == hashright2)
        printf("TAK\n");
    else printf("NIE\n");
}