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
63
64
#include <stdio.h>
#include <vector>

bool hasSolution(int zeros, int ones)
{
	return (zeros + ones) * 2 <= 8 * zeros && 8 * zeros <= (zeros + ones) * 5;
}

std::vector<char> solution(int zeros, int ones)
{
	std::vector<char> data;
	while (0 < zeros && 0 < ones)
	{
		if (zeros == ones)
		{
			data.push_back('c');
			zeros -= 4;
			ones -= 4;
		}
		else if (zeros < ones)
		{
			if (zeros + 4 <= ones)
			{
				data.push_back('o');
				zeros -= 2;
				ones -= 6;
			}
			else
			{
				data.push_back('g');
				zeros -= 3;
				ones -= 5;
			}
		}
		else
		{
			data.push_back('a');
			zeros -= 5;
			ones -= 3;
		}
	}
	data.push_back(0);
	return data;
}

int main()
{
	int n, zeros{0}, ones{0};
	scanf("%d\n", &n);
	for (int i = 0; i < n * 8; ++i)
	{
		char c;
		scanf("%c", &c);
		if (c == '0')
			zeros++;
		else
			ones++;
	}
	if (hasSolution(zeros, ones))
		printf("%s\n", solution(zeros, ones).data());
	else
		printf("NIE\n");
	return 0;
}