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
#include <stdio.h>                                                              
#include <iostream>                                                             
using namespace std;                                                            
                                                                                
const int modulo = 19319;                                                       

                                                                                
int mod(int x) {return x % modulo;}                                             
                                                                                
int main()                                                                      
{                                                                               
    int A = 26;                                                                 
    int  a1 = 1;                                                                

    int H1 = 0;                                                                 
    int  H2 = 0;                                                                
    int prevH2 = H2;                                                            
    char c;                                                                     
                                                                                
    scanf("%d\n");                                                              
                                                                                
    while(scanf("%c", &c) != EOF){                                              
        if(c == '\n') continue;                                                 
        c-= 96;                                                                 
        H1 = mod(H1 + mod(c*a1)); a1 = mod(a1 * A);                             
        H1 = mod(H1);                                                           
                                                                                
        H2 = mod(H2 + c);                                                       
        prevH2 = H2;                                                            
        H2 = mod(H2 * A);                                                       
        H2 = mod(H2);                                                           
    }                                                                           
                                                                                
    H2 = prevH2;                                                                
    if(mod(H1) == mod(H2)) printf("TAK"); else printf("NIE");                   
                                                                                
    return 0;                                                                   
}