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 <iostream>

using namespace std;

int main() {
	std::ios::sync_with_stdio(false);
	long n;
	cin >> n;
	char x;
	long long count = 0;
	long long h1 = 0;
	long long h2 = 0;
	long long h3 = 0;
	long long h1r = 0;
	long long h2r = 0;
	long long h3r = 0;
	long long indy1 = 1;
	long long m1 = 982451653LL;
	long long m2 = 920419823LL;
	long long m3 = 899809343LL;
	while(cin.get(x)) {
//		cout << x << endl;
		if(x >= 'a' && x <= 'z') { // FIXME check this
		//	cout << "processing: " << x << endl;
			long long v = x - 'a' + 1;
			h1 = (h1 + v*indy1) % m1;
			h1r = ((h1r * 10) % m1 + v) %m1;
			indy1 = (indy1 * 10) % m1;
		}

	}
//	cout << "hashen: " << h1 << " / " << h1r << endl;
	if(h1 == h1r) {
		cout << "TAK" << endl;
	} else {
		cout << "NIE" << endl;
	}

	return 0;
}