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
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>

using namespace std;

string is_pal(istream& is) {
	long long n;
	is >> n;
	if(n > 0) {
		long long arrsize  = n >> 1;
		char * arr = new char[arrsize];
		for(long long i = 0 ; i < arrsize; i++ ) {
			char c;
			is >> c;
			arr[i] = c;
		}
		if(n & 0x0000000000000001l == 1) {
			char c;
			is >> c;
		}
		for(long long i = 1; i <= arrsize; i++) {
			char c;
			is >> c;
			if(c != arr[arrsize - i]) {
				return "NIE";
			}
		}
		return "TAK";
	}
	else {
		vector<char> vect;
		unsigned int i = 0;
		int mirrored  = 0;
		char c;
		bool odd_flag = false;
		c = is.get();
		vect.push_back(c);
		while(c != '\n' && c != '\0') {
			c = is.get();
			int idx = i + mirrored;
			if(idx < 0 ) {
				mirrored = 0;
				odd_flag = false;
			}
			if(c==vect[idx]) {
				mirrored -= 2;
			} 
			else if((idx > 0) && (c == vect[idx -1] )){
				mirrored -= 1;
				odd_flag = true;
				cout << "weszlo" << endl;
			}
			else{
				if((i & 0x01 == 0x01)|| odd_flag == true) {
					mirrored = 0;
					odd_flag = false;
				}
				else {
					odd_flag = true;
					mirrored -= 1;
				}
			}
		        vect.push_back(c);
			i++;
		}
		if(mirrored + i == 0) {
			return "TAK";
		}
		else { 
			return "NIE";
		}
	}
}
#ifndef TEST
int main(int argc, char* argv[]) {
#else
int _main(int argc, char* argv[]) {
#endif
	cout << is_pal(cin) << endl;;
}