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

int main(){
	int n;
	string s;
	int one = 0;
	cin >> n >> s;

	for(int i = 0; i<8*n; ++i){
		if(s[i] == '1') one++;
	}

	if(3*n > one || 6*n < one){
		cout << "NIE\n";
		return 0;
	}

	int tr = one/3, czw = 0, pia = 0, szo = 0;
	int m = one%3;

	if(m == 1){
		czw = 1;
		tr--;
		szo = tr+1-n;
		tr -= (tr+1-n)*2;
	}else if(m == 2){
		pia = 1;
		tr--;
		szo = tr+1-n;
		tr -= (tr+1-n)*2;
	}else if(m == 0){
		szo = tr-n;
		tr -= (tr-n)*2;
	}

	while(tr--) cout << "a";
	while(czw--) cout << "c";
	while(pia--) cout << "g";
	while(szo--) cout << "o";
	cout << "\n";
}