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

using namespace std;


map<int, char> mapa
{
    {3, 'a'},
    {4, 'c'},
    {5, 'g'},
    {6, 'o'},
};

int main()
{
    ios_base::sync_with_stdio(0);

    int N;
    cin >> N;
    string s;
    cin >> s;

    int cnt = count(s.begin(), s.end(), '1');
    
    // N * 3
    // // a=3, c=4, g=5, o=6

    // N = 1 | 3, 4, 5, 6
    // N = 2 | 6, 7, 8, 9, 10, 11, 12

    // N = 3 | 3 + 3 + 3 | 3 + 3 + 4 = 10 | 3 + 4 + 4 = 11 | 4 + 4 + 4 = 12 | 4 + 4 + 5 = 13 | 4 + 5 + 5 = 14 | 5 + 5 + 5 = 15 |

    // N * 3 <= x <= N * 6


    if (cnt < N * 3 || cnt > N * 6)
    {
        cout << "NIE\n";
    }
    else
    {
        string res(N, 'a');
        cnt -= 3 * N;

        for (auto &p : res)
        {
            auto ile = min(cnt, 3);

            if (ile)
            {
                p = mapa[3 + ile];
                cnt -= ile;
            }
        }

        cout << res << "\n";

    }
    // cout << "NIE\n";
}