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
37
38
#include <iostream>

using namespace std;

typedef unsigned long long ULL;
const unsigned P=1000000009, LPodst=3, Podst[LPodst]={827476289, 927772311, 118238327};

int main()
{
    ios_base::sync_with_stdio(false);

    ULL bPodst[LPodst];
    for (int i=0; i<LPodst; ++i)
        bPodst[i]=1;

    ULL wart1[LPodst]={}, wart2[LPodst]={};

    int n;
    cin>>n;
    char a;
    while (cin>>a)
    {
        for (int i=0; i<LPodst; ++i)
        {
            wart1[i]=(wart1[i]*Podst[i]+a)%P;
            wart2[i]=(wart2[i]+a*bPodst[i])%P;
            bPodst[i]=(Podst[i]*bPodst[i])%P;
        }
    }
    for (int i=0; i<LPodst; ++i)
        if (wart1[i]!=wart2[i])
        {
            cout<<"NIE"<<endl;
            return 0;
        }
    cout<<"TAK"<<endl;
    return 0;
}