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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
#define getx getchar_unlocked
const ll mod = 1e9 + 7;
ll p[]= {104717, 104723, 104729};

inline int wczytaj(){
    char c;
    int res = 0;
    do{
        c = getx();
    }while(c > '9' || c < '0');
    do{
        res = res*10 + c - '0';
        c = getx();
    }while(c >= '0' && c <= '9');
    return res;
}

ll mnoz[3], gora[3], dol[3];

main(){
    n = wczytaj();
    char c;
    do{
        c = getx();
    }while(c > 'z' || c < 'a');
    for(int i=0; i<3; i++) mnoz[i] = 1;

    do{
        for(int i=0; i<3; i++){
            gora[i] = (gora[i]*p[i]%mod + c-'a'+1) % mod;
            dol[i] = (dol[i] + mnoz[i]*(c-'a'+1)%mod)%mod;
            mnoz[i] = mnoz[i]*p[i]%mod;
        }
        c = getx();
    }while(c >= 'a' && c <= 'z');


    if(gora[0] == dol[0] && gora[1] == dol[1] && gora[2] == dol[2]){
        cout << "TAK";
    }
    else cout << "NIE";
}