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

// 3 -> a
// 4 -> c
// 5 -> g
// 6 -> o

int n;
string s;
int ile1;
int a, c, g, o;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n;
    cin >> s;
    for (auto &c : s)
        if (c == '1')
            ile1++;
    if (ile1 < 3 * n || ile1 > 6 * n)
        cout << "NIE\n";
    else
    {
        ile1 -= 3 * n;
        o = ile1 / 3;
        ile1 %= 3;
        g = ile1 / 2;
        ile1 %= 2;
        c = ile1;
        a = n - o - g - c;
        for (int i = 0; i < a; ++i)
            cout << 'a';
        for (int i = 0; i < c; ++i)
            cout << 'c';
        for (int i = 0; i < g; ++i)
            cout << 'g';
        for (int i = 0; i < o; ++i)
            cout << 'o';
    }
}