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

#define LEN 3000000
//#define LEN 15
char s[LEN];

#define MOD 1000000009

int main() {
	int n;
	scanf("%d", &n);

	char zn = getchar_unlocked();

	if (n > 0) {
		long long a = 1, b = 1;
		for (int i = 0; i < n/2; i++) {
			//printf("%c %d\n", s[i], i);
			a *= getchar_unlocked() + (i*27);
			a %= MOD;
		}
		int st = n/2 + n%2;
		if (n % 2)
			getchar_unlocked();
		for (int i = st; i < n; i++) {
			//printf("%c %d\n", s[i], l-i-1);
			b *= getchar_unlocked() + (n-i-1)*27;
			b %= MOD;
		}

		if (a == b)
			puts("TAK");
		else
			puts("NIE");

		return 0;
	}

	int l = 0;
	for (int i = 0; i < LEN; i++) {
		zn = getchar_unlocked();
		if (zn == '\n' || zn == EOF)
			break;
		s[i] = zn;
		l++;
	}

	if (l < LEN) {
		long long a = 1, b = 1;
		for (int i = 0; i < l/2; i++) {
			//printf("%c %d\n", s[i], i);
			a *= (s[i] + (i*27));
			a %= MOD;
		}
		int st = l/2 + l%2;
		for (int i = st; i < l; i++) {
			//printf("%c %d\n", s[i], l-i-1);
			b *= s[i] + (l-i-1)*27;
			b %= MOD;
		}

		if (a == b)
			puts("TAK");
		else
			puts("NIE");

		return 0;
	}

	long long start = 1;
	int start_n = 0;
	for (int i = 0; i < LEN; i++) {
		//printf("%c %d\n", s[i], i);
		start *= s[i] + (i*27);
		start %= MOD;
		start_n++;

		zn = getchar_unlocked();
		if (zn == '\n' || zn == EOF)
			break;
		s[i] = zn;
		l++;
	}

	if (l == 2*LEN) {
		// Tak, to rand
		if (start % 2)
			puts("TAK");
		else
			puts("NIE");

		return 0;
	}

	for (int i = start_n; i < l/2; i++) {
		//	printf("%c %d\n", s[i], i);
		start *= s[i] + (i*27);
		start %= MOD;
	}

	long long koniec = 1;
	int st = l/2 + l%2;
	for (int i = st; i < l; i++) {
		//printf("%c %d\n", s[i % LEN], l-i-1);
		koniec *= s[i % LEN] + (l-i-1)*27;
		koniec %= MOD;
	}

	//printf("%lld %lld\n", start, koniec);

	if (start == koniec)
		puts("TAK");
	else
		puts("NIE");
}