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
#include <cstdio>
#define FOR(i, a, b) for (int i=(a); (i)<(b); (i)++)
#define PPC(x) __builtin_popcountll((x))
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;

const int S = 2, maxN = 14;

long long val1[S], val2[S], ppow[S],
	mod[S] = {
		35550005550005711,
		40001110001110117
	},
	p[S] = {31, 29};

char T[maxN];

int main()
{
	char* thrash = T;
	size_t thrash2 = 42;
	getline(&thrash, &thrash2, stdin);
	FOR(i, 0, S)
		ppow[i] = 1;
	int dig;
	while ((dig = getchar()) > 96)
	{
		dig -= 96;
	
		val1[0] = (val1[0] * p[0] + dig) % mod[0];
		val2[0] = (val2[0] + ppow[0] * dig) % mod[0];
		ppow[0] = ppow[0] * p[0] % mod[0];
		
		val1[1] = (val1[1] * p[1] + dig) % mod[1];
		val2[1] = (val2[1] + ppow[1] * dig) % mod[1];
		ppow[1] = ppow[1] * p[1] % mod[1];
	}
		
	bool res = true;
	FOR(i, 0, S)
		if (val1[i] != val2[i])
			res = false;
	printf("%s\n", res ? "TAK" : "NIE");
	return 0;
}