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
#include <iostream>

#define PRIME (long long)838997101
#define PRIME2 (long long)94939291

int main() {
  long long c;
  scanf("%lld\n", &c);
  long long hash = 0;
  long long rhash = 0;
  int accumulator = 1;
  bool first = true;
  while (true) {
    c = getchar();
    if (c < (long long)'a' || c > (long long)'z') {
      break;
    }
    if (first) {
      hash = c;
      rhash = c;
      first = false;
    } else {
      accumulator = (accumulator * PRIME2) % PRIME;
      hash = (hash + accumulator*c) % PRIME;
      rhash = (rhash*PRIME2 + c)%PRIME;
    }
  }
  std::cout << ((hash == rhash) ? "TAK" : "NIE") << std::endl;
  return 0;
}