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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<cstdio>
using namespace std;
typedef long long int lld;

const lld P[] = {1000696969, 1000000009, 1000000007, 2038073227, 2038073273};
const lld Q[] = {97, 101, 29, 37, 59};
const lld I[] = {51582318, 841584166, 758620695, 1156744264, 172718074};
lld h1[5];
lld h2[5];
lld m[5];
lld t[5];

int main(void){
	int n;
	scanf("%d",&n);

	n=0;
	register char c;

	for(int i=0;i<5;i++){
		m[i] = 1;
		t[i] = 1;
	}

	while(1){
		c = getchar_unlocked();
		if(c == EOF)
			break;
		if(c < 'a' || 'z' < c)
			continue;

		n++;
		for(int i=0;i<5;i++){
			h1[i] = (h1[i] + t[i]*(c-'a')) % P[i];
			h2[i] = (h2[i] + m[i]*(c-'a')) % P[i];
			m[i] = (m[i]*I[i])%P[i];
			t[i] = (t[i]*Q[i])%P[i];
		}
	}

	for(int i=0;i<5;i++)
		h2[i] = (((h2[i]*t[i])%P[i])*I[i])%P[i];

	for(int i=0;i<5;i++)
		if(h1[i] != h2[i]){
			printf("NIE\n");
			return 0;
		}

	printf("TAK\n");

	return 0;
}