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
#include <cstdio>
#include <vector>
using namespace std;

int size = 80000;
int bits = size * 8;
int* v;

void PutBit(int i, bool bit) {
  int a = i/8;
  int b = i%8;
  if (bit) v[a] |= 1 << b;
  else v[a] &= ~(1 << b);
}

bool GetBit(int i) {
  int a = i/8;
  int b = i%8;
  return v[a] & 1 << b;
}

int main() {
  v = new int[size];
  
  int n; scanf("%d", &n);
  int k = 5;

  if (n != 0) {
    k = min(k, bits / ((n+1)/2));

    char c;
    for (int l=0; l<n; ++l) {
      scanf(" %c", &c);
      c -= 'a';
      if (l < (n+1)/2) {
        for (int i=0; i<k; ++i) {
          PutBit(l*k + i, c &(1 << i));
        }
      } else {
        for (int i=0; i<k; ++i) {
          if (GetBit((n-l-1)*k + i) != bool(c & (1 << i))) {
            printf("NIE\n");
            return 0;
          }
        }
      }
    }
  } else {
    int l = 0;
    char c;
    while (scanf(" %c", &c) == 1) {
      c -= 'a';
      for (int i=0; i<5; ++i) {
        PutBit(l*5+i, c & (1 << i));
      }
      ++l;
    }

    for (int i=0; i<l; ++i) {
      for (int j=0; j<5; ++j) {
        if (GetBit(i*5 + j) != GetBit((l-i-1)*5+j)) {
          printf("NIE\n");
          return 0;
        }
      }
    }
  }
  printf("TAK\n");
  return 0;
}