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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <deque>
using namespace std;

typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define FT first
#define SD second
#define Y first
#define X second

vector<string>token(string a) {
	vector<string>w; a.push_back(' ');
	while (!a.empty()) { w.push_back(a.substr(0, a.find(" "))); a = a.substr(a.find(" ") + 1, a.size() - 1); }return w;
}

map<string, int> mapik;
vector<string> amapik;
int dodaj(string a) { if (mapik.count(a) == 0) { mapik[a] = mapik.size() - 1; amapik.PB(a); }return mapik[a]; }

const int INF = 1000000000;
const LL INFINF = 1000000000000000000LL;

PI moves4[4] = { MP(1, 0), MP(-1, 0), MP(0, 1), MP(0, -1) };
PI move(PI st, PI m)
{
	return MP(st.first + m.first, st.second + m.second);
}

int rows, cols;
bool on_board(PI p)
{
	return p.first >= 0 && p.second >= 0 && p.first < rows && p.second < cols;
}

char tmp_str[1000000];
string scanf_string() {
	scanf("%s", tmp_str);
	return tmp_str;
}

inline bool get_bit(int w, int i) {
	return (w >> i) & 1;
}

// ==========================================================

typedef unsigned char Uchar;

class Paker
{
	int ile_liczb;
	Uchar* miejsce;

public:
	Paker(Uchar* m) : miejsce(m), ile_liczb(0)
	{}

	void push_back(Uchar new_value)
	{
		Uchar val = miejsce[size() / 8];
		val |= new_value << (size() % 8);
		miejsce[size() / 8] = val;
		ile_liczb ++;
	}

	Uchar get(int pos)
	{
		Uchar val = miejsce[pos / 8];
		return (val >> pos % 8) & 7;
	}

	int size() const
	{
		return ile_liczb;
	}
};


class Haszer
{
	LL c, p;
	LL coto;

	LL c_pot;
public:
	Haszer() : Haszer(11, 1000000009)
	{
	}

	Haszer(LL c, LL p)
	{
		c_pot = 1;
		coto = 0;
		this->c = c;
		this->p = p;
	}
	
	LL hasho()
	{
		return coto;
	}

	void push_back(char val)
	{
		coto = (coto * c + val) % p;
	}

	void push_front(char val)
	{
		coto = (coto + val * c_pot) % p;
		c_pot = (c_pot * c) % p;
	}
};

const int HASH_N = 5;
PI paramy[]{ MP(11, 1000000009), MP(101, 1000000007), MP(743, 10000000019), MP(941,10000000061),  MP(607,100000000057) };

int main() {
	scanf("%*d\n");
	//Paker paker(pamiec);

	Haszer lewe[HASH_N];
	Haszer prawe[HASH_N];

	for (int i = 0; i < HASH_N; i++)
	{
		lewe[i] = Haszer(paramy[i].FT, paramy[i].SD);
		prawe[i] = Haszer(paramy[i].FT, paramy[i].SD);
	}

	int c = 0;
	while (c = getchar())
	{
		if ('a' <= c && c <= 'z')
		{
			Uchar val = c - 'a';
			for (int i = 0; i < HASH_N; i++)
			{
				lewe[i].push_back(val);
				prawe[i].push_front(val);
			}
			//paker.PB((Uchar)(c - 'a'));
		}
		else
			break;
	}

	bool palindrom = true;

	for (int i = 0; i < HASH_N; i++)
	{
		if (lewe[i].hasho() != prawe[i].hasho())
			palindrom = false;

	}

	/*for (int i = 0; i < paker.size() / 2; i++)
	{
		if (paker.get(i) != paker.get(paker.size() - i - 1))
		{
			palindrom = false;
			break;
		}
	}*/

	printf("%s\n", palindrom ? "TAK" : "NIE");
	return 0;
}