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

  int n;

  long primes[26][4] = {
      { 31687, 31699, 31721, 31723 },
      { 31727, 31729, 31741, 31751 },
      { 31769, 31771, 31793, 31799 },
      { 31817, 31847, 31849, 31859 },
      { 31873, 31883, 31891, 31907 },
      { 31957, 31963, 31973, 31981 },
      { 31991, 32003, 32009, 32027 },
      { 32029, 32051, 32057, 32059 },
      { 32063, 32069, 32077, 32083 },
      { 32089, 32099, 32117, 32119 },
      { 32141, 32143, 32159, 32173 },
      { 32183, 32189, 32191, 32203 },
      { 32213, 32233, 32237, 32251 },
      { 32257, 32261, 32297, 32299 },
      { 32303, 32309, 32321, 32323 },
      { 32327, 32341, 32353, 32359 },
      { 32363, 32369, 32371, 32377 },
      { 32381, 32401, 32411, 32413 },
      { 32423, 32429, 32441, 32443 },
      { 32467, 32479, 32491, 32497 },
      { 32503, 32507, 32531, 32533 },
      { 32537, 32561, 32563, 32569 },
      { 32573, 32579, 32587, 32603 },
      { 32609, 32611, 32621, 32633 },
      { 32647, 32653, 32687, 32693 },
      { 32707, 32713, 32717, 32719 },
  };
  long bigPrime = 32749;

  long* leftMatrix;
  long* rightMatrix;
  long* resultMatrix;

  void multiply() {
    long r0 = leftMatrix[0] * rightMatrix[0] + leftMatrix[1] * rightMatrix[2];
    long r1 = leftMatrix[0] * rightMatrix[1] + leftMatrix[1] * rightMatrix[3];
    long r2 = leftMatrix[2] * rightMatrix[0] + leftMatrix[3] * rightMatrix[2];
    long r3 = leftMatrix[2] * rightMatrix[1] + leftMatrix[3] * rightMatrix[3];
    resultMatrix[0] = r0 % bigPrime;
    resultMatrix[1] = r1 % bigPrime;
    resultMatrix[2] = r2 % bigPrime;
    resultMatrix[3] = r3 % bigPrime;
  }

  bool isLetter(int symbol) {
    return symbol >= 'a';
  }

  int main() {
    int symbol;
    while (!isLetter(symbol = getchar())) {}

    long forward[4];
    long backward[4];
    for (int i = 0; i < 4; i++) {
      forward[i] = primes[symbol - 'a'][i];
      backward[i] = primes[symbol - 'a'][i];
    }

    for (symbol = getchar(); isLetter(symbol); symbol = getchar()) {
      leftMatrix = forward;
      rightMatrix = primes[symbol - 'a'];
      resultMatrix = forward;
      multiply();

      rightMatrix = backward;
      leftMatrix = primes[symbol - 'a'];
      resultMatrix = backward;
      multiply();
    }

    if (forward[0] == backward[0]
        && forward[1] == backward[1]
        && forward[2] == backward[2]
        && forward[3] == backward[3]) {
      printf("TAK");
    } else {
      printf("NIE");
    }
    return 0;
  }