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
//#include<bits/stdc++.h>
#include<vector>
#include<iostream>
#define rep(i,k,n) for(ll i= (ll) k;i< (ll) n;i++)
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)((v).size())
#define pb push_back
#define ft first
#define sd second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long long INF = 1e18L + 1;
const int IINF = 1e9 + 1;

using namespace std;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define DBG(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const ll p_cnt = 3, mod = 1e9 + 7;

vector<ll> prms = {37, 263, 269}, prms_pow(p_cnt, 1), f_hsh(p_cnt, 0), b_hsh(p_cnt, 0);

int main()
{
#ifndef LOCAL
	ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
	ll n; cin >> n;
	char c;
	while(cin >> c){
		rep(i, 0, p_cnt){
			f_hsh[i] = (f_hsh[i] * prms[i] + c) % mod;
			b_hsh[i] = (b_hsh[i] + c * prms_pow[i]) % mod;
			prms_pow[i] = (prms_pow[i] * prms[i]) % mod;
		}
	}
	rep(i, 0, p_cnt){
		if(f_hsh[i] != b_hsh[i]){
			cout << "NIE\n";
			return 0;
		}
	}
	cout << "TAK\n";
    return 0;
}