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
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;


const int S = 25*100*1000;
char chars[S];


struct H {
    long long int hash;
    long long int mod;
    long long int a;
    long long int currentA;
    //long long int a1;

    H(long long int mod, long long int a){
        hash = 0;
        this->mod = mod;
        this->a = a;
        currentA = 1;
        //this->a1 = mod;
    }

    void addBack(char c)
    {
        hash = (hash * a)%mod;
        hash = (hash + c)%mod;
        currentA = (currentA * a)%mod;
    }

    void addFront(char c)
    {
        hash = (hash + (c*currentA)%mod)%mod;
        currentA = (currentA * a)%mod;
    }
};

inline char fromInput(){
    char c;
    scanf("%c", &c);
    return c;
}

int charsIx = 0;
inline char fromArray(){
    return(chars[charsIx++]);
}

int main(){
    int n;
    cin >> n;
    string str;
    getline(cin,str);
    char (*func)();

    if( n != 0) {
         func = fromInput;
    } else {
        cin.get(chars, S);
        int sn = strlen(chars);
        if( sn+1 == S)
        {
            cout<<"NIE"<<endl;
            return 0;
        }
        n = sn;
        func = fromArray;
    }

    H hb1(550404389, 357728887);
    H he1(550404389, 357728887);

    H hb2(429224897, 250249799);
    H he2(429224897, 250249799);


    for(int i = 0; i < n/2; i++){
        char c = func();
        hb1.addFront(c);
        hb2.addFront(c);
    }

    if((n%2) == 1) {
        char c = func();
        hb1.addFront(c);
        hb2.addFront(c);
        he1.addBack(c);
        he2.addBack(c);
    }

    for(int i = (n/2)+(n%2); i < n; i++){
        char c = func();
        he1.addBack(c);
        he2.addBack(c);
    }

    cout << ((he1.hash == hb1.hash && he2.hash == hb2.hash) ? "TAK" : "NIE" ) << endl;

    return 0;
}