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
#include <iostream>
#include <cmath>
#include <algorithm>

const long long pot = 31;
const long long mod = 2760727302517;

int main() {
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    char c;
    long long h1 = 0, h2 =0;
    long long current_pot = 1;
    while (std::cin >> c) {
        long long x = c - 'a';
        h1 += x * current_pot;
        h1 %= mod;
        h2 = (pot * h2 + x) % mod;
        current_pot *= pot;
        current_pot %= mod;
    }
    if (h1 == h2) {
        std::cout << "TAK";
    } else {
        std::cout << "NIE";
    }
}