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
#include <bits/stdc++.h>

using namespace std;

const int P=2137;
const long long M=213769669;
const long long L=20000000;

long long spo(long long a, long long n)
{
	long long w=1;
	while (n>0)
	{
		if (n&1) w*=a;
		a*=a;
		n=n>>1;
		w%=M;
		a%=M;
	}
	return w;
}

int main()
{
	ios_base::sync_with_stdio(false);
	long long n,hp=0,ht=0,r,p;
	char x;
	cin >> n;
	if (n>0)
	{
		for (long long i=0; i<n; i++)
		{
			cin >> x;
			r=x-96;
			hp+=spo(P,i)*r;
			ht+=spo(P,n-i-1)*r;
			hp%=M;
			ht%=M;
		}
	}
	else
	{
		while (cin >> x)
		{
			r=x-96;
			hp+=spo(P,n)*r;
			ht+=spo(P,L-n)*r;
			hp%=M;
			ht%=M;
			n++;
		}
		p=spo(P,L-n+1);
		ht*=spo(p,M-2);
		ht%=M;
	}
		if (hp==ht) cout << "TAK";
		else cout << "NIE";
}