1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdio>

long long m1=991375631, m2=14424204097, q1=571, q2=859, hp1, hp2, ht1, ht2, qt1=1, qt2=1;
char c='0';

int main()
{
	while('0'<=c&&c<='9')c=getchar_unlocked();
	c=getchar_unlocked();
	while('a'<=c&&c<='z')
	{
		hp1*=q1; hp2*=q2;
		hp1+=c; hp2+=c;
		hp1%=m1; hp2%=m2;
	    ht1+=(qt1*c); qt1*=q1;
		ht2+=(qt2*c); qt2*=q2;
		ht1%=m1; qt1%=m1; 
		ht2%=m2; qt2%=m2;
		c=getchar_unlocked();
	}
	if(hp1==ht1 && hp2==ht2)puts("TAK");
	else puts("NIE");
}