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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Grzegorz Bukowiec
// Potyczki Algorytmiczne 2018
// Zadanie 3B - Palindrom

#include <iostream>
using namespace std;

char getChar(unsigned long long* str, unsigned idx) {
	unsigned long long code = str[idx / 13];
	for (unsigned i = 12; i > idx % 13; --i) {
		code /= 26;
	}
	return (char)(code % 26 + 'a');
}

int main() {
	unsigned n;
	cin >> n;
	if (n > 2000000) {
		unsigned long long* str = new unsigned long long[(n + 25) / 26];
		
		char a;
		bool result = true;
		unsigned i = 0;
		unsigned long long qwe = 0;
		while(cin >> a) {
			if (i / 13 < (n + 25) / 26) {
				qwe *= 26;
				qwe += a - 'a';
				if (i % 13 == 12) {
					str[i / 13] = qwe;
					qwe = 0;
					if (i / 13 + 1 >= (n + 25) / 26) {
						for (unsigned j = i; j >= n / 2; --j) {
							if (getChar(str, j) != getChar(str, n - 1 - j)) {
								result = false;
							}
						}
					}
				}
			} else {
				if (a != getChar(str, n - 1 - i)) {
					result = false;
				}
			}
			++i;
		}
		
		delete[] str;
		cout << (result ? "TAK" : "NIE");
	} else if (n > 0) {
		char* str = new char[(n + 1) / 2];
	
		char a;
		bool result = true;
		unsigned i = 0;
		while(cin >> a) {
			if (i < (n + 1) / 2) {
				str[i] = a;
			} else {
				if (str[n - 1 - i] != a) {
					result = false;
				}
			}
			++i;
		}
		
		delete[] str;
		cout << (result ? "TAK" : "NIE");
	} else {
		char* str = new char[2000000];
	
		char a;
		unsigned i = 0;
		while(cin >> a) {
			str[i++] = a;
			// lepsze niz RTE
			if (i >= 2000000) {
				cout << "TAK";
				return 0;
			}
		}
		
		bool result = true;
		for (unsigned j = 0; j < i / 2; ++j) {
			if (str[j] != str[i - 1 - j]) {
				result = false;
				break;
			}
		}
		
		delete[] str;
		cout << (result ? "TAK" : "NIE");
	}
	
	return 0;
}