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
#include <cstdlib>
#include <cstdio>
#include <tuple>

#define MOD 1000000007

#define BASE 31

using data_t = long long;

#define LTR_APPEND(data, base, val) \
    data = (data * base) % MOD; \
    data = (data + val) % MOD;
#define RTL_APPEND(data, nmult, base, val) \
    data = (data + (val * nmult) % MOD) % MOD; \
    nmult = (nmult * base) % MOD;

int main() {
    int n;
    scanf("%i ", &n);
    data_t ltr1 = 0;
    data_t rtl1 = 0, rtl1m = 1;
    for (int i = 0; ; i++) {
        int c = getchar_unlocked();
        if (c < 'a' || c > 'z')
            break;
        c -= 'a';
        LTR_APPEND(ltr1, BASE, c)
        RTL_APPEND(rtl1, rtl1m, BASE, c)
    }
    printf("%s\n", ltr1 == rtl1 ? "TAK" : "NIE");
    return 0;
}