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
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
using namespace std;

long long Q = 1e9 +33;

long long v(char c)
{
	return (c - 'a');
}

long long pot(long long a,long long k)
{
	if(k==0)
	return 1;

	if(k%2==1)
	return (a*pot(a,k-1)%Q);

 	long long e=pot(a,k/2);
	return((e*e)%Q);
}

 
int main()
{
	int n;
	cin >> n;
	
	char c;
	
	long long p = 37;
	
	long long H1 = 0;
	long long H2 = 0;
	
	long long r = pot(p,Q-2);
	long long k = 0;
	
	while(cin >> c)
	{
		k++;
		
		H1 += v(c);
		H1 = (H1 * p) % Q;
		
		H2 += v(c);
		H2 = (H2 * r) % Q; 
		
	}
	
	long long p_pot = pot(p,k+1);
	
	H2 = (H2 * p_pot) % Q;
	
	if( H1 == H2 )
	cout << "TAK";
	
	else
	cout << "NIE"; 
return 0;
}