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
#include <cstdio>
#include <cctype>
using namespace std;
typedef unsigned long long ULL;

const int K = 4;
const ULL MOD[K] = {4294966981, 4294966909, 4294966877, 4294966661};
const ULL P[K] = {4294966477, 4294966337, 4294966297, 4294966243};

ULL a[K], b[K], pow[K];

int main() {
  for (int i=0; i<K; ++i) pow[i] = 1;

  scanf("%*d ");
  for (;;) {
    int c = getchar();
    if (!islower(c)) break;
    for (int i=0; i<K; ++i) {
      a[i] = (a[i]*P[i] + c) % MOD[i];
      b[i] = (b[i] + pow[i]*c) % MOD[i];
      pow[i] = (pow[i] * P[i]) % MOD[i];
    }
  }

  bool res = true;
  for (int i=0; i<K; ++i) if (a[i] != b[i]) res = false;
  puts(res ? "TAK" : "NIE");

  return 0;
}