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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
long long mod=1000000009;
long long po(long long a, int b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    long long c=po(a, b/2);
    if(b%2==0){
        return c*c%mod;
    }
    else{
        return (a*c%mod)*c%mod;
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char c=0;
    int x1=30, x2=31, n;
    int x1o=po(x1, mod-2), x2o=po(x2, mod-2);
    long long h1=0, h1o=0, h2=0, h2o=0;
    cin>>n;
    if(n==0){
        while(true){
            if(cin>>c){
                h1*=x1;
                h1+=c-'a'+1;
                h1%=mod;
                h1o*=x1o;
                h1o+=c-'a'+1;
                h1o%=mod;
                h2*=x2;
                h2+=c-'a'+1;
                h2%=mod;
                h2o*=x2o;
                h2o+=c-'a'+1;
                h2o%=mod;
                n++;
            }
            else{
                break;
            }
        }
    }
    else{
        for(int i=0; i<n; i++){
            cin>>c;
            h1*=x1;
            h1+=c-'a'+1;
            h1%=mod;
            h1o*=x1o;
            h1o+=c-'a'+1;
            h1o%=mod;
            h2*=x2;
            h2+=c-'a'+1;
            h2%=mod;
            h2o*=x2o;
            h2o+=c-'a'+1;
            h2o%=mod;
        }
    }
    if(h1o*po(x1, n-1)%mod==h1 and h2o*po(x2, n-1)%mod==h2){
        cout<<"TAK";
    }
    else{
        cout<<"NIE";
    }
}