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
66
67
68
69
70
71
#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector<int> v = {6, 5, 4, 3};

void f(int i, int sum, vector<int>& ans, vector<int>& res, int n)
{
    if(sum < 0 or i > 3) return;
    if(sum == 0)
    {
        if(ans.size() == n)
        {
            res = ans;
            return;
        }
    }
    int add;
    if(v[i] <= sum)
    {
        ans.push_back(v[i]);
        f(i, sum-v[i], ans, res, n);
        ans.pop_back();
    }
    f(i+1, sum, ans, res, n);
    
}

vector<int> solve(int sum, int n)
{
    vector<int> ans;
    vector<int> res;
    f(0, sum, ans, res, n);
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n; cin>>n;
    string s; cin>>s;
    int jed = 0;
    for(int i = 0; i < 8*n; i++)
    {
        if(s[i] == '1') jed++;
    }
   
    vector<int> r;
    r = solve(jed, n);
    
    for(auto x : r)
    {
        //cout<<x<<" ";
        if(x == 3)
        cout<<"a";
        else if(x == 4)
        cout<<"c";
        else if(x == 5)
        cout<<"g";
        else if(x == 6)
        cout<<"o";
    }
    if(r.empty())
    cout<<"NIE\n";
    
    
    return 0;
}