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

long long int K = 29;
long long int MOD = 86028121;


int main()
{
    long long hashFront = 0;
    long long hashBack = 0;
    int n;
    char c;
    long long int k = 1;
    scanf("%d\n", &n);

    while (scanf("%c", &c) != EOF) {
        if (c == '\n') break;
        hashBack *= K;
        hashBack %= MOD;
        hashBack += (int)c;
        hashBack %= MOD;

        hashFront += (k * (int)c);
        hashFront %= MOD;

        if (k == 1) k = K;
        else{
            k *= K;
            k %= MOD;
        }
    }

    if (hashFront == hashBack) 
        printf ("TAK\n");
    else
        printf ("NIE\n");

    return 0;
}