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
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;

bool sumTab(int tab[])
{
	int sum = 0;
	for (int i = 0; i < 15; i++)
		sum += tab[i];
	if (sum == 18)
		return true;
	return false;
}
int addToTab(int tab[],string x) 
{
	int zad, podzad,odp;
	zad = int(x[0]) - 48;
	switch (x[1]){
		case 'A':
		{podzad = 0; }break;
		case 'B':
		{podzad = 1; }break;
		case 'C':
		{podzad = 2; }break;
	}
	if (zad == 5) {
		odp = 12 + podzad;
		if (tab[odp] < 2)
			return odp;
	}
	else {
		odp = ((zad - 1) * 3) + podzad;
		if (tab[odp] < 1)
			return odp;
	}
	return -1;
}
int main()
{
	int n,odp;
	cin >> n;
	int tab[15] = {0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0};
	bool answer = false;
	string x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		odp = addToTab(tab, x);
		if (odp != -1)
			tab[odp]++;
		if (sumTab(tab)){
			answer = true;
			break;
		}
	}
	if (answer)
		cout << "TAK";
	else
		cout << "NIE";
	return(0);
}