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

using namespace std;
using ll = long long;

const int mod = 999399971, p = 967;

#define gc getchar

int main() {
    char c = 0;
    while (c < 97) {
        c = gc();
    }

    int h1 = 0, h2 = 0, pp = 1;
    while (c > 96) {
        h1 = (1LL * h1 * p + c - 'a' + 1) % mod;
        h2 = (0LL + h2 + 1LL * pp * (c - 'a' + 1)) % mod;
        pp = (1LL * pp * p) % mod;
        c = gc();
    }

    if (h1 == h2) {
        cout << "TAK\n";
    }
    else {
        cout << "NIE\n";
    }
}