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;

uint16_t n, i, j;
uint16_t tasks[5][3]; // tasks[rounds][divisions]
char round, letter;

int main(void) {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	for(i = 0; i < 5; i++)
		for(j = 0; j < 3; j++)
			tasks[i][j] = 0;

	cin >> n;

	if(n < 18) {
		cout << "NIE";
		return 0;
	}

	for(i = 0; i < n; i++) {
		cin >> round >> letter;
		tasks[round-'1'][letter-'A'] += 1;
	}

	for(i = 0; i < 5; i++)
		for(j = 0; j < 3; j++)
			if(tasks[i][j] < (1 + i/4)) {
				cout << "NIE";
				return 0;
			}

	cout << "TAK";

	return 0;
}