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
#include <iostream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	char sign;
	bool odd[28];
	uint64_t sum[28];
	for (int i=0;i<28;i++)
	{
		odd[i]=false;
		sum[i]=0;
	}
	uint64_t length = 0;
	while (cin >> sign)
	{
		int position = (int)sign-int('a');
		sum[position] += length;
		odd[position] = !odd[position];
		length++;
	}
	if (length == 1)
	{
		cout << "TAK" << endl;
		return 0;
	}
	bool even = false;
	for (int i=0;i<28;i++)
	{
		if (odd[i])
		{
			if (even)
			{
				cout << "NIE" << endl;
				return 0;
			}
			even = true;
		}
	}

	for (int i=0;i<28;i++)
	{
		if (!odd[i])
		{
			if (sum[i]%(length-1) != 0)
			{
				cout << "NIE" << endl;
				return 0;
			}
		}
	}
	cout << "TAK" << endl;
	return 0;
}