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
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;

char a;
int n;
unsigned long long h,hw,g,gw,p=1,pk=1;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n;
    while(cin>>a)
    {

        n=a-97;

        h+=p*n;
        p*=29;

        hw*=29;
        hw+=n;

        if(h>368934870)  h%=2000000011;
        if(p>2000000010)  p%=2000000011;
        if(hw>636094623000000000) hw%=2000000011;

        g+=pk*n;
        pk*=29;

        gw*=29;
        gw+=n;

        if(g>368934870)  g%=2000000033;
        if(pk>2000000010)  pk%=2000000033;
        if(gw>636094623000000000) gw%=2000000033;

    }

    h%=2000000011;
    hw%=2000000011;
    g%=2000000033;
    gw%=2000000033;

    if(h==hw && g==gw) cout<<"TAK";
    else cout<<"NIE";

    return 0;
}