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
#include <stdint.h>
#include <iostream>

using namespace std;

class Buffer
{
public:
	Buffer()
	{
		mask = 0;
		size = 0;
		helper[0] = 5;
		buf = (uint64_t *)(&helper[0]);
	}

	void put(char c)
	{
		size++;
		if (mask == 0)
			*buf = 0;

		*buf |= uint64_t(c - 96) << mask;
		mask += 5;
		if (mask == 40)
		{
			buf_stl += helper;
			mask = 0;
		}
	}

	void flush()
	{
		buf_stl += helper;
	}

	char get(int index)
	{
		int aa = (index / 8) * 5;
		int str_mask = (index % 8) * 5;
		uint64_t m = uint64_t(31) << str_mask;
		return char((*((uint64_t *)&(buf_stl[(index / 8) * 5])) & m) >> str_mask) + 96;
	}

	int getSize() const
	{
		return size;
	}

private:
	int mask;
	int size;
	uint64_t* buf;
	char helper[8];
	std::string buf_stl;
};

int main()
{
	Buffer b;
	int t;
	cin >> t;
	char c;
	std::cin.get(c);
	while (std::cin.get(c))
	{
		if (c == 10)
			break;
		b.put(c);
	}
	b.flush();
	int sz = b.getSize();
	if (sz % 2 == 0)
	{
		for (int i = 0; i < (sz / 2); i++)
		{
			if (b.get(i) != b.get((sz-1) - i))
			{
				cout << "NIE" << endl;
				return 0;
			}
		}
	}
	else
	{
		for (int i = 0; i < (sz / 2)-1; i++)
		{
			if (b.get(i) != b.get((sz-1)- i))
			{
				cout << "NIE" << endl;
				return 0;
			}
		}
	}
	cout << "TAK" << endl;
	return 0;
}