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
#include <bits/stdc++.h>

using namespace std;

const int P = 257, M = 1046284763;

int mul(int w, int u) {
    return (long long)w * u % M;
}

int main() {
    
    int n;
    scanf("%d", &n);
    
    int hashRight = 0;
    int hashLeft = 0;
    int powerLeft = 1;
    char c;
    while (~scanf(" %c", &c)) {
        hashRight = ((long long)hashRight * P + c - 'a' + 1) % M;
        hashLeft = (hashLeft + mul(c - 'a' + 1, powerLeft)) % M;
        powerLeft = mul(powerLeft, P);
    }
    
    printf(hashLeft == hashRight ? "TAK\n" : "NIE\n");
    
    return 0;
}