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
47
48
49
50
51
#include <iostream>

using namespace std;

int main() {

    int n;
    cin >> n;

    string string, result;
    cin >> string;

    int ones = 0;
    int zeros = 0;
    for (char const &c: string) {
        if (c == '1') {
            ones++;
        } else if (c == '0') {
            zeros++;
        }
    }

    if (ones < 3 * n || ones > 6 * n) {
        cout << "NIE" << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (ones < zeros) {
            result.push_back('a');
            ones -= 3;
            zeros -= 5;
        } else if (ones == zeros) {
            result.push_back('c');
            ones -= 4;
            zeros -= 4;
        } else if (ones - 2 > zeros) {
            result.push_back('o');
            ones -= 6;
            zeros -= 2;
        } else {
            result.push_back('g');
            ones -= 5;
            zeros -= 3;
        }
    }

    cout << result << endl;

    return 0;
}