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

char chars[4] = {'a', 'c', 'g', 'o'};

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
char c;
int ones = 0;
for(int i = 0; i < 8 * n; i++) {
    cin >> c;
    ones += (c == '1');
}
if(ones < 3 * n || ones > 6 * n) {
    cout << "NIE";
    return 0;
}
ones -= 3 * n;
string sol = "";
while(ones > 3) {
    sol += chars[3];
    ones -= 3;
}
sol += chars[ones];
for(int i = sol.size(); i < n; i++) {
    sol += chars[0];
}
cout << sol;
}