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
#include <iostream>

using namespace std;

/*

2
1100000011110111

8
1011111010101100011011011010001010100011111111110001001001011010

1
00011000

*/

string solve(const int ones_count, const int n)
{
    if(ones_count<3*n||ones_count>6*n)
        return "NIE";

    char tab[7];
    tab[3]='a';
    tab[4]='c';
    tab[5]='g';
    tab[6]='o';

    string result;
    int ones_left=ones_count;
    int n_left=n;
    for(int i=0;i<n;++i)
    {
        for(int j=3;j<=6;++j)
            if(ones_left-j>=3*(n_left-1)&&ones_left-j<=6*(n_left-1))
            {
                ones_left-=j;
                --n_left;
                result += tab[j];
                break;
            }
    }

    return result;
}

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ones_count=0;
    for(char c : s)
        ones_count += c == '1' ? 1 : 0;
    cout << solve(ones_count, n);
    return 0;
}