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

const int M = 5;
const unsigned long long P[M] = {
	37,
	105701,
  179425331,
  1000000007,
  32416189909L
};

int main() {
	int n;
	scanf("%d", &n);
	char x;
	std::vector<unsigned long long> a(M), b(M), pp(M, 1);
	while((x = getchar())) {
		if (x == '\n' || x == ' ') {
		  if (!a[0] && !b[1]) continue;
			break;
		}
		for (int i = 0; i < M; i++) {
			a[i] = a[i] * P[i] + x;
			b[i] += pp[i] * x;
			pp[i] *= P[i];
		}
	}
	printf(a == b ? "TAK\n" : "NIE\n");
	return 0;
}