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 <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;

void appendChars(char c, int amount, stringstream& ss){
	for(int i = 0; i < amount; i++) ss << c;
}

int main(){
	int n, zeros, ones;
	char digit;
	zeros = ones = 0;
	cin >> n;
	for(int i = 0; i < 8*n; i++){
		cin >> digit;
		if(digit == '1') ones++;
		else zeros++;
	}
	zeros -= n;
	ones -= 2*n;
	if(zeros < 0 || ones < 0){
		cout << "NIE";
	} 
	else {
		int x = zeros - ones;
		int large_step = abs(x) / 3;
		int small_step = abs(x) % 3;
		int symmetrical_steps = n - large_step - small_step;
		if(symmetrical_steps < 0 || symmetrical_steps % 2 != 0) {
			cout << "NIE";
		}
		else {
			stringstream ss;
			appendChars(x > 0 ? 'a' : 'o', large_step, ss);
			appendChars(x > 0 ? 'c' : 'g', small_step, ss);
			appendChars('a', symmetrical_steps / 2, ss);
			appendChars('o', symmetrical_steps / 2, ss);
			cout << ss.str();
		}
	}
	return 0;
}