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
#include <cstdio>
//#include <stdio.h>
#include <functional>
#include <string>
#include <cstring>
//#include <string.h>

int main(void) {
    int n;
    std::hash<std::string> hash;
    scanf("%d\n", &n);
    char *buff;
    char a;
    if(n != 0) {
        constexpr int size = 2000000; // 2MB * 10 = 20MB = max input
//        constexpr int size = 2; // 2MB * 10 = 20MB = max input
        if(n == 1) {
            printf("TAK\n");
            return 0;
        }
        if(n <= 2*size) {
            buff = new char[n/2];
            int idx = 0;
            for(idx = 0; idx < n/2; ++idx) {
                scanf("%c", &buff[idx]);
            }
            if(n % 2) {
                scanf("%c", &a);
            }
            for(--idx; idx >= 0; --idx) {
                scanf("%c", &a);
//                printf("i:%d  %c != %c ?\n", idx, buff[idx], a);
                if(buff[idx] != a) {
                    printf("NIE\n");
                    delete buff;
                    return 0;
                }
            }
            printf("TAK\n");
        } else {
            size_t hashes[10];
            int wordPartSize = n/10;
            int bytesLeft = n/2 - wordPartSize*5;
            int buffSize = wordPartSize + bytesLeft;
            
            buff = new char[buffSize];
            memset(buff, 0, buffSize);
            
            int idx;
            //4x :
            for(int i=0; i<4; ++i) {
                for(idx = 0; idx < wordPartSize; ++idx) {
                    scanf("%c", &buff[idx]);
                }
                std::string s(buff);
                hashes[i] = hash(s);
            }
            //1x:
            for(idx = 0; idx < buffSize; ++idx) {
                scanf("%c", &buff[idx]);
            }
            {
                std::string s(buff);
                hashes[4] = hash(s);
            } // free this string

            //skip one char if odd
            if(n % 2) {
                scanf("%c", &a);
            }

            //reversing 
            //1x:
            for(idx = buffSize-1; idx >= 0; --idx) {
                scanf("%c", &buff[idx]);
            }
            {
                std::string s(buff);
                hashes[5] = hash(s);
            } // free this string
            memset(buff, 0, buffSize);
            //4x :
            for(int i=0; i<4; ++i) {
                for(idx = wordPartSize-1; idx >= 0; --idx) {
                    scanf("%c", &buff[idx]);
                }
                std::string s(buff);
                hashes[i+6] = hash(s);
            }
            
            for(int i=0; i<5; ++i) {
//                printf("i:%d  %zd != %zd ?\n", i, hashes[i], hashes[9-i]);
                if(hashes[i] != hashes[9-i]) {
                    printf("NIE\n");
                    delete buff;
                    return 0;
                }
            }
            printf("TAK\n");
        }
    } else {
        printf("NIE\n");
        return 0;
    }
    delete buff;
    return 0;
}