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
#include <bits/stdc++.h>

using namespace std;

int n;

char c;

long long int p = 1e9 + 9;

/*long long int pot (long long int n, int x) {
    if (x == 0) return 1;
    if (x % 2 == 0) {
    	long long int d = pot(n, x/2);
		return (d*d)%p;
	}	
    else return (pot(n, x-1)*n)%p;
}*/
long long int pot (long long int n, int x) {
	int acc = 1;
	while (x != 0) {
		if (x % 2 == 1) acc = (acc * n)%p;
		x/=2;
		n = (n*n)%p; 
	}
	return acc;
}
long long int hash1, hash2;
int main () {
    
    cin >> n;
    n = 0;
    while (cin >> c) {
    //for (int i = 0; i < n; i++) {
		//c = s[i];
		hash1 += ((c-'a')*pot(26, n)%p);
		hash2 += ((c-'a')*pot(26, p-n-1)%p);
		hash1 %= p;
		hash2 %= p;
		n++;
    }
    if (hash1 == (hash2*pot(26, n-1))%p) cout << "TAK" << endl;
    else cout << "NIE" << endl;
}