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
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	char c;

	do c = getchar(); while (c != '\n');

	int N = 3;
	unsigned long long hash1[] = {0, 0, 0};
	unsigned long long hash2[] = {0, 0, 0};
	const unsigned long long MOD[] = {1000000007, 4000000007, 6000000007};
	const unsigned long long BASE[] = {2, 3, 29};
	unsigned long long mul[] = {BASE[0], BASE[1], BASE[2]};

	do {
		c = getchar();
		if (c != '\n') {
			for (int i = 0; i < N; i++) {
				hash1[i] += (c-'a'+1)*mul[i];
				hash2[i] = (hash2[i]+c-'a'+1)*BASE[i];

				hash1[i] = hash1[i] % MOD[i];
				hash2[i] = hash2[i] % MOD[i];
				mul[i] = mul[i]*BASE[i];
				mul[i] = mul[i] % MOD[i];
			}
		}
	} while (c != '\n');

	bool pal = true;
	for (int i = 0; i < N; i++)
		if (hash1[i] != hash2[i]) pal = false;

	printf("%s\n", pal ? "TAK" : "NIE");

	return 0;
}