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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>

using namespace std;

void solve() {
    char cc[8];
    cc[3] = 'a';
    cc[4] = 'c';
    cc[5] = 'g';
    cc[6] = 'o';

    int n;
    cin >> n;
    string s;
    cin >> s;
    int zeroes = 0;
    int ones = 0;
    for (char c : s) {
        if (c == '0') {
            zeroes++;
        } else {
            ones++;
        }
    }
    string ans = "";
    while (zeroes + ones > 0) {
        int diff = ones - zeroes;
        int target = -1;
        if (diff <= -2) {
            target = 3;
        } else if (diff == 0) {
            target = 4;
        } else if (diff == 2) {
            target = 5;
        } else if (diff >= 4) {
            target = 6;
        } else {
            cout << "NIE\n";
            return;
        }
        ans += cc[target];
        ones -= target;
        zeroes -= 8 - target;
    }
    if (zeroes < 0 || ones < 0) {
        cout << "NIE\n";
        return;
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(12);

    int T = 1;
    //cin >> T;
    for (int t = 0; t < T; t++) {
        solve();
    }

    return 0;
}