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
#include <bits/stdc++.h>

int32_t main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);

	int n;
	std::string binary;
	std::cin >> n >> binary;

	int total = 0;
	for (auto i : binary) if (i == '1') ++total;

	if (total < 3 * n || total > 6 * n)
	{
		std::cout << "NIE\n";
	}
	else
	{
		int b3 = n, b4 = 0, b5 = 0, b6 = 0;
		total -= (3 * n);
		if (total <= n) b4 = total;
		else
		{
			b4 = n;
			total -= n;
			if (total <= n) b5 = total;
			else
			{
				b5 = n;
				total -= n;
				b6 = total;
			}
		}
		b3 -= b4;
		b4 -= b5;
		b5 -= b6;
		while (b3--) std::cout << 'a';
		while (b4--) std::cout << 'c';
		while (b5--) std::cout << 'g';
		while (b6--) std::cout << 'o';
		std::cout << '\n';
	}

	return 0;
}