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

using namespace std;

const char letters[3] = {'o', 'c', 'g'};

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, x = 0;
    string input;
    cin >> n >> input;
    for(int i = 0; i < input.size(); ++i) {
        if(input[i] == '1')
            ++x;
    }

    if(x < 3 * n || x > 6 * n) {
        cout << "NIE";
    } else {
        int k = (x - 3 * n + 2) / 3;
        int a = n - k, b = k - 1;
        for(int i = 0; i < a; ++i) {
            cout << 'a';
        }
        for(int i = 0; i < b; ++i) {
            cout << 'o';
        }
        if(k > 0)
            cout << letters[(x - 3 * n - 3 * k + 6) % 3];
    }
}