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 int lli;

const lli MOD = 1000000007;
const lli p = 127;
lli rp;

lli pot(lli a, lli n) {
	if (n == 0)
		return 1;
	
	if (n%2 == 1)
		return (a*pot(a, n-1))%MOD;
	else
		return pot((a*a)%MOD, n/2);
}

int main() {
	rp = pot(p, MOD-2);
	int n = 0;
	scanf("%*d%*c");
	
	char c;
	
	lli h1 = 0, h2 = 0;
	
	while (2) {
		scanf("%c", &c);
		if (c == '\n')
			break;
		
		h1 = (h1*p + c)%MOD;
		h2 = (h2*rp + c)%MOD;
		n++;
	}
	
	h2 = (h2*pot(p, n-1))%MOD;
	
	if (h1 == h2)
		printf("TAK\n");
	else
		printf("NIE\n");
	
	return 0;
}