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
// pal2018.cpp : Defines the entry point for the console application.
//




#include "stdio.h"

#define	LL	1000000

char	 xx[LL+4], yy[LL+4];

int		 debug = 0;

int main()
{
	int	 i, j, p, l, e, c, d, s;

	l	= 0;
	p	= 0;
	while ((c=getchar())<'a')
	{
		p++;
		if (c>='0' && c<='9')
			l	= 10 * l + c - '0';
	}

	if (l==0)
	{
		fseek(stdin, 0, SEEK_END);
		e	= ftell(stdin);
		l	= e - 20;
		if (l<p)
			l	= p;
		
		fseek(stdin, l, SEEK_SET);
		while (l<e && (c=getchar())>='a')
			l++;

		l	= l - p;
	}

	if (debug>0)
		printf("%d %d\n", p, l);

	d	= l / 2;
	e	= l + p;
	while (d > 0)
	{
		s	= d < LL ? d : LL;
		d	-= s;
		
		fseek(stdin, p, SEEK_SET);
		fread(xx, s, 1, stdin);
		p	+= s;

		fseek(stdin, e - s, SEEK_SET);
		fread(yy, s, 1, stdin);
		e	-= s;

		if (debug>0)
			printf("%s %s\n", xx, yy);

		i	= 0;
		j	= s - 1;

		while (i<s)
			if (xx[i++]!=yy[j--])
			{
				i	= s;
				d	= -1;
			}
	}

	if (d==0)
		printf("TAK\n");
	else
		printf("NIE\n");

	return 0;
}