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

unsigned char letters[100000] = { 0 };

int main() {
	int n = 0;
	unsigned char l = 0;
	std::cin >> n;
	int ones = 0;
	int zeros = 0;
	for (int i = 0; i < n; i++) {
		for (int bits = 0; bits < 8; bits++) {
			std::cin >> l;
			if (l == '1')
				ones++;
			else
				zeros++;
		}
	}

	for (int i = 0; i < n; i++) {
		if (ones == zeros) {
			letters[i] = 'c';
			ones -= 4;
			zeros -= 4;
		}
		else if (ones > zeros) {
			if (ones == 5) {
				letters[i] = 'g';
				ones -= 5;
				zeros -= 3;
			}
			else {
				letters[i] = 'o';
				ones -= 6;
				zeros -= 2;
			}
		}
		else if (ones < zeros) {
			letters[i] = 'a';
			ones -= 3;
			zeros -= 5;
		}
	}
	if (zeros == 0 && ones == 0)
		std::cout << letters;
	else
		std::cout << "NIE";
}