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
#include <iostream>
using namespace std;

int main()
{
	int n,nr;
	char t[3];
	unsigned int A = 0, B = 0, C = 0;
	scanf(" %i", &n);
	for (int i = 0; i < n; i++)
	{
		scanf(" %s",&t);
		nr = t[0]-'0';
		switch (t[1]) {
		case 'A':
			if (nr == 5 && A >= 16)
			nr++;
			A = A | (1 << (nr - 1));
			break;
		case 'B':
			if (nr == 5 && B >= 16)
			nr++;
			B = B | (1 << (nr - 1));
			break;
		case 'C':
			if (nr == 5 && C >= 16)
			nr++;
			C = C | (1 << (nr - 1));
			break;
		}
		if (A == 63 && B == 63 && C == 63)
		{
			printf("TAK\n");
			return 0;
		}
	}
	printf("NIE\n");
	return 0;
}