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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include <stdio.h>


typedef unsigned long long  lli;

typedef unsigned int  uint;


static const int CHARS_NUM = 'z' - 'a' + 1;

static const int BUFF_SIZE = 2 * 1024 * 1024 + sizeof (int) - 1;


static int  iLen;
static bool fResult = false;

static lli aPrimes[] = { 31, 1000000007, 34359737771 };

static char aBuff[BUFF_SIZE];


static void ClearBuff()
{
	for (int i = 0; i < BUFF_SIZE; ++i)
		aBuff[i] = 0;
}


static void CheckBuff()
{
	for (int i = 0; i < BUFF_SIZE; ++i)
		if (aBuff[i])
			return;

	fResult = true;
}


static inline void ProcessChar1stHalfKN(char c, int iPos)
{
	uint k = iPos * CHARS_NUM + c;

	for (int i = 0; i < sizeof (aPrimes) / sizeof (*aPrimes); ++i)
	{
		lli km = k * aPrimes[i];

		uint iOffset = (uint) (km % (BUFF_SIZE - sizeof (uint) + 1));
		uint iValue  = (uint) (km / (BUFF_SIZE - sizeof (uint) + 1));

		uint * p = (uint *) (aBuff + iOffset);

		*p += iValue;
	}
}


static inline void ProcessChar2ndHalfKN(char c, int iPos)
{
	uint k = iPos * CHARS_NUM + c;

	for (int i = sizeof (aPrimes) / sizeof (*aPrimes) - 1; i >= 0; --i)
	{
		lli km = k * aPrimes[i];

		uint iOffset = (uint) (km % (BUFF_SIZE - sizeof (uint) + 1));
		uint iValue  = (uint) (km / (BUFF_SIZE - sizeof (uint) + 1));

		uint * p = (uint *) (aBuff + iOffset);

		*p -= iValue;
	}
}


static void SolveKnownLen()
{
	char  c;
	bool  fProcessing = false;
	int   i = -1;
	int   iPos = 0;

	ClearBuff();

	for (;;)
	{
		if (scanf("%c", &c) != 1)
			break;

		if (c < 'a' || c > 'z')
		{
			if (fProcessing)
				break;

			continue;
		}

		fProcessing = true;
		i++;
		c -= 'a';

		if (i < iLen / 2)
		{
			ProcessChar1stHalfKN(c, iPos++);
			continue;
		}

		if (i >= (iLen + 1) / 2)
		{
			ProcessChar2ndHalfKN(c, --iPos);
		}
	}

	CheckBuff();
}


static void CheckNNBuff(int iSize)
{
	for (int i = 0; i < iSize / 2; ++i)
	{
		if (aBuff[i] != aBuff[iSize - i - 1])
			return;
	}

	fResult = true;
}


static void SolveNotKnownLen()
{
	char  c;
	bool  fProcessing = false;
	int   i = 0;

	for (;;)
	{
		if (scanf("%c", &c) != 1)
			break;

		if (c < 'a' || c > 'z')
		{
			if (fProcessing)
				break;

			continue;
		}

		fProcessing = true;
		
		if (i >= BUFF_SIZE)
			return;

		aBuff[i++] = c;
	}

	CheckNNBuff(i);
}


int main(int argc, char * argv[])
{
	scanf("%d", &iLen);

	if (iLen == 0)
		SolveNotKnownLen();
	else
		SolveKnownLen();

	if (fResult)
		printf("TAK");
	else
		printf("NIE");

	return 0;
}