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
#include<bits/stdc++.h>
#define getchar getchar_unlocked
#pragma GCC optimize("O3")
using namespace std;
const int S=2;
typedef uint_fast64_t ll;//long long ll;

const ll M[3] = {ll(1e9 + 7), ll(1e9 + 181), ll(1e9 + 363)};

const ll p[3] = {29, 37, 43};

ll pp[3];

ll h[3][2];

int ile[256];

ll wsp[32][S];

int main()
{
	int n;
	scanf("%d", &n);
	n = 0;
	srand(time(0));
	for(int i=0; i < 32; ++i){
		wsp[i][0] = i;
		wsp[i][1] = (rand() + 1) % M[1];
	}
	
	for(int i=0; i < 3; ++i)
		pp[i] = p[i];
	char c;
	while(c = getchar())
	{
		if(c >= 'a' && c <= 'z')
			break;
	}
	
	while(true)
	{
		if(c == EOF || c == '\n')break;
		++n;
		
		++ile[c];
		
		for(int i=0; i < S; ++i)
		{
			h[i][0] += wsp[(c - 'a' + 1)][i]*pp[i];
			h[i][0] %= M[i];
			
			h[i][1] *= p[i];
			h[i][1] += p[i]*wsp[(c - 'a' + 1)][i];
			h[i][1] %= M[i];
			
			pp[i] = (pp[i] * p[i]) % M[i];
		}
		//putchar_unlocked(c);
		c = getchar();
		
	}
	
	int np = 0;
	
	for(int i=0; i < 256; ++i)
		if(ile[i] & 1)
			++np;
			
	if(np != 0 && (n & 1) == 0)
	{
		puts("NIE");
		return 0;
	}
	if(np != 1 && (n & 1))
	{
		puts("NIE");
		return 0;
	}
	//puts("CHECK");
	for(int i=0; i < 3; ++i)
	{
		//cout << h[i][0] << " " << h[i][1] << endl;
		if(h[i][0] != h[i][1]){
			puts("NIE");
			return 0;
		}
	}
	
	puts("TAK");
}