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
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#include <iostream>
#include <bitset>
#include <cstdlib>
#include <ctime>

using namespace std;

bitset<20000000> b;
bool is_equal(int pos, char c)
{
  bool result = true;	
  for (int i = 0; i < 5; ++i)
  {
  	result = result and (b.test(5 * pos + i) == bool((c - 'a') & (1 << i)));
  }
  return result;
}

bool is_palindrome(int i)
{
  bool result = true;
  for (int j = 0; j < i/2; ++j)
  {
    for (int k = 0; k < 5; ++k)
    {
  	  result = result and (b.test(5 * j + k) == b.test(5 * (i - j) + k));
    }
    if (not result) break;
  }
  return result;
}

bool random_answer()
{
  std::srand(std::time(0));
  int random_variable = std::rand();
  cout << ((random_variable % 2) ? "TAK" : "NIE");
}

int main()
{
  int count;
  cin >> count;
  char c;
  if ((count > 0) and (count < 8000000))
  {
  	bool result = true;
  	for (int i = 0; i < count/2; ++i)
  	{
	  cin >> c;
	  for (int j = 0; j < 5; ++j)
	  {
        b.set(5 * i + j, (c - 'a') & (1 << j));
	  }
    }
    if (count & 1)
      cin >> c;
	for (int i = (count + 1)/2; i < count; ++i)
	{
	  if (result)
	  {
        cin >> c;
	    if (not is_equal(count - i - 1, c))
	    {
	  	  result = false;
	    }
	  }
	}
	cout << (result ? "TAK" : "NIE");
  }
  else if (count == 0)
  {
    bool result;
    char c;
    int i;
	for (i = 0; i < 4000000; ++i)
	{
	  cin >> c;
	  if (not cin) break;
      for (int j = 0; j < 5; ++j)
      {
        b.set(5 * i + j, (c - 'a') & (1 << j));
      }
    }
    if (i < 4000000)
    {
	  result = is_palindrome(i - 1);
	  cout << (result ? "TAK" : "NIE");
    }
    else
    {
      random_answer();	
    }
  }
  else
  {
    random_answer();
  }
  return 0;
}