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

using namespace std;

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

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    string message;
    cin >> n;

    cin >> message;

    int one_counter = 0;

    for(char i : message) {
        if(i == '1')
            one_counter++;
    }

    if(one_counter < 3*n or one_counter > 6*n)
        cout << "NIE" << endl;
    else {
        one_counter -= 3*n;
        for(int i = 0; i < n; i++) {
            int next_letter = min(one_counter, 3);
            one_counter -= next_letter;
            cout << letters[next_letter];
        }
        cout<<endl;
    }

    return 0;
}