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
#include <iostream>
using namespace std;

long long lp[27] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,101,103};
long long hash_1[13];
long long hash_2[13];
long long hi[13] = {107,109,113,127,131,137,139,149,151,157,163,167,173};
long long mn[13] = {107,109,113,127,131,137,139,149,151,157,163,167,173};

int main() {
    int n;
    cin>>n;
    char x;
   // for(int i = 0; i < 13;i++)h[i]=1;
    while( cin >> x )
    {
        for(int i = 0; i < 13;i++){
            hash_1[i] += lp[x-'0']*mn[i];
            mn[i]*=hi[i];
            hash_2[i] = hash_2[i]*hi[i]+lp[x-'0']*hi[i];
        }
        //cout<<"char: "<< x << endl;
    }
    bool ok = true;
    for(int i = 0; i < 13;i++){
        if(hash_1[i]!=hash_2[i])ok=false;
     
    }
    if(ok){
        cout<<"TAK\n";
    }
    else{
        cout<<"NIE\n";
    }
    return 0;
}