1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

int n,ones;
char c;

int main() {
    cin >> n;
    for(int i=0; i<8*n; i++) {
        cin >> c;
        if(c == '1') ones++;
    }
    if(ones < 3*n || ones > 6*n) {
        cout << "NIE" << endl;
        return 0;
    }
    int overflow = ones-3*n;
    for(int i=0; i<n; i++) {
        if(overflow >= 3) { cout << "o"; overflow -= 3; }
        else if(overflow == 2) { cout << "g"; overflow -= 2; }
        else if(overflow == 1) { cout << "c"; overflow -= 1; }
        else if(overflow == 0) cout << "a";
    }
}