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 <cstdio>

using namespace std;

typedef unsigned long long ull;

const ull MOD = 10000002563;
const ull BASE = 10000002553;

bool check_palindrome(int n) {
    ull first_hash = 0;
    ull second_hash = 0;
    ull pow = 1;
    int l_end = n / 2 - 1;
    int r_beg = (n + 1) / 2;
    char c;
    
    for (int i = 0; i <= l_end; ++i) {
        c = getchar();
        first_hash = (first_hash * BASE) % MOD;
        first_hash = (first_hash + (c - 'a')) % MOD;
    }
    if (r_beg - l_end > 1) { c = getchar(); }
    for (int i = r_beg; i < n; ++i) {
        c = getchar();
        ull temp = ((c - 'a') * pow) % MOD;
        second_hash = (second_hash + temp) % MOD;        
        pow = (pow * BASE) % MOD;
    }

    return first_hash == second_hash;
}

bool check_palindrome() {
    ull forward_hash = 0;
    ull backward_hash = 0;
    ull pow = 1;
    char c;
    c = getchar();
    
    while (c != '\n') {
        ull temp = ((c - 'a') * pow) % MOD;
        forward_hash = (forward_hash + temp) % MOD;
        pow = (pow * BASE) % MOD;

        backward_hash = (backward_hash * BASE) % MOD;
        backward_hash = (backward_hash + (c - 'a')) % MOD;

        c = getchar();
    }
    
    return forward_hash == backward_hash;
}

int main() {
    int n;
    scanf("%d\n", &n);

    bool is_palindrome = false;
    if (n == 0) {
        is_palindrome = check_palindrome();
    } else {
        is_palindrome = check_palindrome(n);
    }
    
    if (is_palindrome) {
        printf("TAK\n");
    } else {
        printf("NIE\n");
    }
    
    return 0;
}