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
 98
 99
100
101
#include <iostream>
using namespace std;

const int SIZE = 1200000;
char start[SIZE];
char endd[SIZE];
int count[26] = { 0 };
int length;

bool checkCounts() {
	int odd = 0;

	for (int i = 0; i < 26; i++) {
		if (count[i] % 2) {
			odd++;
		}
	}

	if (length % 2) {
		if (odd == 1) {
			return true;
		} else {
			return false;
		}
	} else {
		if (odd == 0) {
			return true;
		} else {
			return false;
		}
	}
}

bool isPalindrome() {
	if (length <= SIZE) {
		for (int i = 0; i < length / 2; i++) {
			if (start[i] != start[length - 1 - i]) {
				return false;
			}
		}
	} else if (length <= 2*SIZE) {
		for (int i = 0; i < length / 2; i++) {
			if (length - 1 - i < SIZE) {
				if (start[i] != start[length - 1 - i]) {
					return false;
				}
			} else {
				if (start[i] != endd[length - 1 - i - SIZE]) {
					return false;
				}
			}
		}
	} else {
		int k = 0;
		for (int i = 0; i < SIZE; i++) {
			if (i < (length % SIZE)) {
				if (start[i] != endd[(length % SIZE) - 1 - i]) {
					return false;
				}
			} else {
				if (start[i] != endd[SIZE - 1 - k]) {
					return false;
				}
				k++;
			}
		}
	}

	return true;
}

int main() {
	int l;
	cin >> l;

	char c;
	while (cin >> c) {
		length++;
		count[((int) (c)) - 97]++;

		if (length <= SIZE) {
			start[length - 1] = c;
		} else if (length <= 2*SIZE) {
			endd[length - 1 - SIZE] = c;
		} else {
			endd[(length - 1) % SIZE] = c;
		}
	}

	if (!checkCounts()) {
		cout << "NIE";
	} else {
		if (!isPalindrome()) {
			cout << "NIE";
		} else {
			cout << "TAK";
		}
	}

	return 0;
}