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
#include <stdio.h>
#define READ_BUFFER_SIZE 1000000
using namespace std;

int n;
char S[READ_BUFFER_SIZE+1];

#define NUM_OF_CHECKERS 3
long long X[NUM_OF_CHECKERS][5] = {
    /* {A, P, wL, wR, a} */
    {34183, 46819, 0, 0, 1},
    {12347201, 87654569, 0, 0, 1},
    {14287723, 26522971, 0, 0, 1},
};

int main() {
    scanf("%d\n", &n);
    bool finish = false;
    while(!finish && fgets(S, READ_BUFFER_SIZE, stdin)) {
        for(int j=0; S[j] && !finish; ++j) {
            if (S[j]<'a' || S[j]>'z') finish = true;
            else {
                for (int i=0; i<NUM_OF_CHECKERS; ++i) {
                    X[i][2] = ((X[i][2]*X[i][0])%X[i][1] + (S[j]-'a'))%X[i][1];
                    X[i][3] = (((S[j]-'a')*X[i][4])%X[i][1] + X[i][3])%X[i][1];
                    X[i][4] = (X[i][4]*X[i][0])%X[i][1];
                }
            }
        }
    }

    for (int i=0; i<NUM_OF_CHECKERS; ++i) {
        if (X[i][2] != X[i][3]) {
            printf("NIE\n");
            return 0;
        }
    }
    printf("TAK\n");
}