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
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

const int H = 3;

int p[H] = {31, 345679, 12347}, m[H] = {1000000009, 1000000013, 1000000009}, pw[H];
int h1[H], h2[H];

int main() {
	FOR(i,H) pw[i] = 1;
	int n;
	char c;
	scanf("%d ", &n);
	while (scanf("%c", &c) != -1) {
		if (c < 'a' || 'z' < c) break;
		FOR(i,H) {
			h1[i] = (1LL * h1[i] * p[i] + c) % m[i];
			h2[i] = (1LL * pw[i] * c + h2[i]) % m[i];
			pw[i] = 1LL * pw[i] * p[i] % m[i];
		}
	}
	bool res = 1;
	FOR(i,H) res &= h1[i] == h2[i];
	printf("%s\n", res ? "TAK" : "NIE");
	return 0;
}