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
#include <iostream>
#include <map>

int main() {
    using namespace std;
    int n;
    cin >> n;
    map<int, char> D {
        {3, 'a'},
        {4, 'c'},
        {5, 'g'},
        {6, 'o'}
    };
    string A;
    cin >> A;
    int ones = 0;
    for(int i = 0; i < A.size(); i++)
        if(A[i] == '1')
            ones += 1;
    if(ones < 3 * n || 6 * n < ones) {
        cout << "NIE\n";
    } else {
        string result;
        while(ones - 3 * n > 3) {
            result += 'o';
            ones -= 6;
            n -= 1;
        }
        while(n > 1) {
            result += 'a';
            ones -= 3;
            n -= 1;
        }
        result += D[ones];
        ones = 0;
        n -= 1;
        cout << result << "\n";
    }
    return 0;
}