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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 1e9+696969;
const int MM = 1e9+9;

int n, h, r, hh, rr;

inline int add(int a, int b, int mod = M) {
	return (a+b)%mod; 
}

inline int mult(int a, int b, int mod = M) {
	return ((ll)a*b)%mod;
}


int main() {
	
	scanf("%d ",&n);
	
	int p = 1;
	int pp = 1;
	char c;
	
	for(;;){
		
		c=getchar_unlocked();
		if(c < 97) break;
		
		int a = c-'a';
		
		h = add(h, mult(p,a));
		r = add(mult(r,29),a);
		
		hh = add(hh, mult(pp,a,MM), MM);
		rr = add(mult(rr,29,MM),a,MM);
		
		
		p = mult(p,29);
		pp = mult(pp,29,MM);
	}
	
	if(h == r && hh == rr) puts("TAK");
	else puts("NIE");
	
}