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
#include<iostream>
#include<stack>
//p = 70032301 , q = 1000000007
using namespace std;
string t, w;
long long hash_w[5], hash_t[5], pot[5]={1,1,1,1,1};
long long p[5] ={70032301,1000000007,104579, 104597, 104623 };
int main()
{
ios_base::sync_with_stdio(0);
int n, i;
char z;	
cin >> n;
while(cin >> z){
for(i = 0; i < 5; ++i) {
	hash_w[i] = hash_w[i]*p[i] + int(z);
	hash_t[i] = hash_t[i] + int(z)*pot[i];
	pot[i] = p[i] * pot[i];
}	
	
}
for(i = 0; i < 5; ++i) {
	if(hash_w[i] != hash_t[i]) {
		cout <<"NIE";
		return 0;
	}	
}
cout <<"TAK";

return 0;
}