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

const int c = 31, mod = 1e9 + 9;
long long pw(long long a, long long b)
{
	if (b == 0) return 1;
	if (b % 2) return a * pw(a, b - 1) % mod;
	return pw(a * a % mod, b / 2);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	if (n)
	{
	long long h1 = 0;
	for (int i = 0; i < n / 2; i++)
	{
		char x; cin >> x;
		h1 *= c;
		h1 += (x - 'a' + 1);
		h1 %= mod;
	}
	char a;
	if (n % 2) cin >> a;
	long long h2 = 0;
	for (int i = 0; i < n / 2; i++)
	{
		char x; cin >> x;
		h2 += (x - 'a' + 1) * pw(c, i);
		h2 %= mod;
	}
	if (h1 == h2) cout << "TAK\n";
	else cout << "NIE\n";
	}
	else
	{
		vector<char> A;
		char a;
		while (cin >> a) A.push_back(a);
		for (int i = 0; i < A.size() / 2; i++)
			if (A[i] != A[A.size() - i - 1]) { cout << "NIE\n"; return 0; }
		cout << "TAK\n";
	}
}