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
65
66
67
68
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>


using namespace std;


int main()
{
	unsigned n;
	scanf("%u", &n);

	pair<unsigned, unsigned> bits;
	scanf("\n");
	for (unsigned i = 0; i < 8 * n; ++i)
	{
		char b;
		scanf("%c", &b);
		if (b == '0') ++bits.first;
		else ++bits.second;
	}

	if (bits.first < 2 * n || bits.second < 3 * n)
	{
		printf("NIE");
		return 0;
	}

	bits.first -= n;
	bits.second -= 2 * n;

	const unsigned cnt = bits.first >= bits.second ? (bits.first - bits.second) / 3 : (bits.second - bits.first) / 3;
	if (bits.first > bits.second)
	{
		printf("%s", string(cnt, 'a').c_str());
		bits.first -= cnt * 4;
		bits.second -= cnt;
	}
	else if (bits.second > bits.first)
	{
		printf("%s", string(cnt, 'o').c_str());
		bits.first -= cnt;
		bits.second -= cnt * 4;
	}

	while (bits.first != bits.second)
	{
		if (bits.first > bits.second)
		{
			printf("c");
			bits.first -= 3;
			bits.second -= 2;
		}
		else if (bits.second > bits.first)
		{
			printf("g");
			bits.first -= 2;
			bits.second -= 3;
		}
	}

	printf("%s", string((bits.first + bits.second) / 10, 'a').c_str());
	printf("%s", string((bits.first + bits.second) / 10, 'o').c_str());

	return 0;
}