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

using namespace std;

int A[6];
int B[6];
int C[6];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, i;
	string s;
	cin >> n;
	while (n--)
	{
		cin >> s;
		switch(s[1])
		{
			case 'A':
				A[s[0] - 48]++;
				break;
			case 'B':
				B[s[0] - 48]++;
				break;
			case 'C':
				C[s[0] - 48]++;
				break;
		}
	}
	for(i = 1; i < 5; i++)
	{
		if(A[i] < 1 || B[i] < 1 || C[i] < 1)
		{
			cout << "NIE\n";
			return 0;
		}
	}
	if(A[5] < 2 || B[5] < 2 || C[5] < 2)
	{
		cout << "NIE\n";
		return 0;
	}
	cout << "TAK\n";
	return 0;
}