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
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define FOROP(i,a,b,op) for(int i=a;i<b;op)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define PB push_back
#define FI first
#define SE second
#define umap unordered_map
#define uset unordered_set
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define ALL(X) (X).begin(),(X).end()
#ifndef DEBUG
#define endl (char)10
#endif
using namespace std;
using ll = long long;

#define TEST_WITH 5

/*
ll bases[TEST_WITH] = {67, 101, 97, 229, 41, 151, 241, 73, 313, 37};
ll moduli[TEST_WITH] = {1000000007, 1000000009, 1000000021, 1000000033,
    1000000087, 1000000093, 1000000097, 1000000103, 1000000123, 1000000181};
*/

ll bases[TEST_WITH] = {67, 101, 97, 229, 41};
ll moduli[TEST_WITH] = {1000000007, 1000000009, 1000000021, 1000000033, 1000000087};

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x;
    cin >> n;
    char c = 19;
    ll fwd[TEST_WITH];
    ll bck[TEST_WITH];
    ll pwrs[TEST_WITH];
    FOR(i,0,TEST_WITH){
        fwd[i] = bck[i] = 0;
        pwrs[i] = 1;
    }
    while(cin >> c){
        x = c - 'a';
        FOR(i,0,TEST_WITH){
            fwd[i] = (bases[i] * fwd[i] + x) % moduli[i];
            bck[i] = (bck[i] + pwrs[i] * x) % moduli[i];
            pwrs[i] = (pwrs[i] * bases[i]) % moduli[i];
        }
    }
    FOR(i,0,TEST_WITH) if(fwd[i] != bck[i]){
        cout << "NIE" << endl;
        return 0;
    }
    cout << "TAK" << endl;
}