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
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <vector>

using namespace std;

constexpr char MAPPING[5] = {
	'\0',
	'a',
	'c',
	'g',
	'o'
};

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

	int n;
	int cs[2] = { 0, 0 };
	char tmp;

	cin >> n;

	for(int i = 0; i < (n << 3); i++) {
		cin >> tmp;
		cs[tmp - '0']++;
	}

	cs[0] -= n;
	cs[1] -= (n << 1);
	auto [opc, ol] = div(cs[1], n);

	if(cs[0] < 0 || cs[1] < 0 || opc < 1 || opc > 4 || (opc == 4 && ol != 0)) {
		cout << "NIE\n";
		return 0;
	}

	vector<int> raw(n, opc);

	transform(raw.begin(), raw.begin() + ol, raw.begin(), [](int a) { return a + 1; });
	transform(raw.begin(), raw.end(), ostream_iterator<char>(cout, ""), [](int a) { return MAPPING[a]; });

	return 0;
}