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



template <long long s, long long q>
class Hash {
	long long qPow;
	long long value1;
	long long value2;
public:
	Hash() : qPow(1), value1(0), value2(0) {}
	void push(long long x) {
//		value1 += qPow * x;
//		value1 &= s;
		value1 = (qPow * x + value1) & s;
//		qPow *= q;
//		qPow &= s;
		qPow = (qPow * q) & s;
//		value2 *= q;
//		value2 += x;
//		value2 &= s;
		value2 = (value2 * q + x) & s;
	}
	bool err() { return value1 != value2; }
	void show() {
		printf("%lld\n", value1);
		printf("%lld\n", value2);
		printf("\n");
	}
};



const int bufSize = 1024 * 1024;
char buf[bufSize];

bool solve() {

	Hash<0x7fffffff, 123444789> h0;
	Hash<0x7fffffff,  44338853> h1;
	Hash<0x7fffffff,   7212177> h2;
	Hash<0x7fffffff,   3299821> h3;
	Hash<0x3fffffff, 777445557> h4;
	Hash<0x3fffffff, 324354651> h5;
	Hash<0x3fffffff,   9874329> h6;
	Hash<0x1fffffff,    332213> h7;
	Hash<0x1fffffff,     54637> h8;
	Hash<0x1fffffff,      1009> h9;

	char c;

	bool eof = false;
	while (eof == false) {
		size_t n = fread(buf, 1, bufSize, stdin);
		if (n != bufSize && feof(stdin) != 0) eof = true;
		for (int i=0; i<n; ++i) {
			if (buf[i] < 'a' || 'z' < buf[i]) continue;
			h0.push(buf[i]);
			h1.push(buf[i]);
			h2.push(buf[i]);
			h3.push(buf[i]);
			h4.push(buf[i]);
			h5.push(buf[i]);
			h6.push(buf[i]);
			h7.push(buf[i]);
			h8.push(buf[i]);
			h9.push(buf[i]);
		}
	}

	if (h0.err()) return false;
	if (h1.err()) return false;
	if (h2.err()) return false;
	if (h3.err()) return false;
	if (h4.err()) return false;
	if (h5.err()) return false;
	if (h6.err()) return false;
	if (h7.err()) return false;
	if (h8.err()) return false;
	if (h9.err()) return false;
	return true;
}



int main() {
	printf("%s\n", solve() ? "TAK" : "NIE");
	return 0;
}