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
41
42
43
44
45
46
#include <bits/stdc++.h>

using namespace std;

const char useful[] = {'a', 'c', 'g', 'o'};
const int counter[] = {3, 4, 5, 6};

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;

    string in;
    cin >> in;

    int count_ones = 0;
    for (const auto &c: in) {
        count_ones += c == '1';
    }

    if (count_ones < 3 * n || 6 * n < count_ones) {
        cout << "NIE\n";
        exit(0);
    }

    string answer;
    while (n > 0) {
        for (int t = 0; t < 4; ++t) {
            int next_n = n - 1;
            int next_ones = count_ones - counter[t];
            
            if (3 * next_n <= next_ones && next_ones <= 6 * next_n) {
                answer.push_back(useful[t]);
                count_ones = next_ones;
                n = next_n;
                break;
            }
        }
    }

    cout << answer;
    return 0;
}