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
34
35
36
#include <iostream>
using namespace std;
int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    long long hp1=0, hp2=0, ht1=0, ht2=0, pod=1019, mod1=1000000033, mod2=1000000009, pot1=1, pot2=1;
    int n;
    cin >> n;
    char c=getchar_unlocked();
    c=getchar_unlocked();
    while (c!=EOF && c!='\n')
    {
        //cout << c << "\n";
        int lit=c-'a'+1;
        hp1*=pod;
        hp1+=lit;
        hp1%=mod1;
        hp2*=pod;
        hp2+=lit;
        hp2%=mod2;
        ht1+=lit*pot1;
        ht1%=mod1;
        ht2+=lit*pot2;
        ht2%=mod2;
        pot1*=pod;
        pot1%=mod1;
        pot2*=pod;
        pot2%=mod2;
        c=getchar_unlocked();
    }
    if (hp1==ht1 && hp2==ht2)
        cout << "TAK\n";
    else
        cout << "NIE\n";
}