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;
typedef long long ll;

const ll pl = 333;
const ll MOD =  179424743;
const ll MOD2 = 2147483647;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    char c;
    ll h1 = 0, h2 = 0;
    ll h3 = 0, h4 = 0;
    ll pom1 = 1, pom2 = 1;
    while (cin >> c) {
        h1 = (h1 * pl + c) % MOD;
        h2 = (h2 + c * pom1) % MOD;
        h3 = (h3 * pl + c) % MOD2;
        h4 = (h4 + c * pom2) % MOD2;
        pom1 = (pom1 * pl) % MOD;
        pom2 = (pom2 * pl) % MOD2;
    }
    if(h1 == h2 && h3 == h4) cout << "TAK";
    else cout << "NIE";
}