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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <stdio.h>
using namespace std;
const long long P=17389;
const long long P2=17383;
const long long P3=17231;
const long long P4=16349;
int main(){
srand(time(NULL));
int n;
cin >> n;
if (n){
        long long h=0;
        long long h2=0;
        long long h3=0;
        long long h4=0;
        long long h5=0;
        long long h6=0;
        long long h7=0;
        long long h8=0;
        long long h9=0;
        long long h10=0;
        int t[27];
        int t2[27];
        for (int i=0; i<27;i++){
            t[i]=i+1;
            t2[i]=i+1;
        }
        for (int i=0; i<27;i++){
            int tmp1 = rand()%27;
            int tmp2 = rand()%27;
            int tmp3 = rand()%27;
            int tmp4 = rand()%27;
            swap (t[tmp1],t[tmp2]);
            swap (t2[tmp3],t2[tmp4]);
        }
        /*for (int i=0; i<27;i++){
            cout << t[i]<<" ";
        }
        cout << endl;
        for (int i=0; i<27;i++){
            cout << t2[i]<<" ";
        }
        cout << endl;*/
        int l=n/2;
        int r=n/2;
        long long p=P;
        long long p2=P2;
        long long p3=P3;
        long long p4=P4;
    for (int i=0; i<l;i++){
        char tmp;
        cin >> tmp;
        int tmp2=tmp-'a'+1;
        int tmp3=t[tmp2-1];
        int tmp4=t2[tmp2-1];
        h+=(tmp2)*p;
        h3+=(27-(tmp2))*p2;
        h5+=(tmp3)*p3;
        h7+=(tmp4)*p4;
        h9+=(27-tmp4)*p;
        p+=P;
        p2+=P2;
        p3+=P3;
        p4+=P4;
    }
    if (n%2){
    char tmp;
    cin >>  tmp;
    }
    for (int i=0; i<r;i++){
        char tmp;
        cin >> tmp;
        p-=P;
        p2-=P2;
        p3-=P3;
        p4-=P4;
        int tmp2=tmp-'a'+1;
        int tmp3=t[tmp2-1];
        int tmp4=t2[tmp2-1];
        h2+=(tmp2)*p;
        h4+=(27-tmp2)*p2;
        h6+=tmp3*p3;
        h8+=tmp4*p4;
        h10+=(27-tmp4)*p;
    }
    /*cout <<h<<" "<< h2<<endl;
    cout <<h3<<" "<< h4<<endl;
    cout <<h5<<" "<< h6<<endl;
    cout <<h7<<" "<< h8<<endl;
    cout <<h9<<" "<< h10<<endl;*/
    if (h==h2 && h3==h4 && h5==h6 && h7==h8&&h9==h10){
        cout << "TAK"<<endl;
    }else{
        cout << "NIE"<<endl;
}
}else{
    string a;
    n++;
    bool czek=0;
    getchar();
while (n++){
    if (n<1000*1000+2){
        char tmp = getchar();
        if (tmp>='a'&& tmp<='z'){
        a+=tmp;
        }else{
        break;
        }
    }else{
        czek=1;
        char tmp=getchar();
    }
}
bool wynik=0;
if (!czek){
int tmp=a.size()-1;
for (int i=0; i<=tmp;i++){
    if (a[i]!=a[tmp-i]){
        wynik=1;
    }
}
}else{
wynik=rand()%2;
}
if (!wynik){
    cout << "TAK"<<endl;
}else{
    cout << "NIE"<<endl;
}
}
}