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 <iostream>
#include <cstdio>
#include <cmath>

#define MOD1 34186049
#define MOD2 15487429

using namespace std;


int main()
{
	int n;
	char c;
	int pow1 = 1;
	int pow2 = 1;
	int p1 = 31;
	int p2 = 23;

	int h1a = 0, h1b = 0, h2a = 0, h2b = 0;

	scanf("%d", &n);
	c = getchar();
	c = getchar();

	while (c >= 'a' && c <= 'z')
	{
		int x = c - 'a' + 1;
		h1a = (h1a * p1 + x) % MOD1;
		h1b = (h1b + pow1 * x) % MOD1;

		pow1 = (pow1 * p1) % MOD1;

		h2a = (h2a * p2 + x) % MOD2;
		h2b = (h2b + pow2 * x) % MOD2;

		pow2 = (pow2 * p2) % MOD2;

		c = getchar();
	}

	if (h1a == h1b && h2a == h2b)
		printf("TAK\n");
	else
		printf("NIE\n");

	return 0;
}