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

typedef long long ll;

vector<ll> sum_up(ll a, ll k){
    vector<ll> pos = {1,2,3,4}, result(k, 1);
    result[k-1] = 0;
    ll m = a - k + 1;
    if(m <= 0 || a > k*4) return {};
    else{
        if(m <= 4){
            result[k-1] = m;
        }
        else{
            ll i = 0;
            while(m > 4 && i < k - 1){
                if(result[i] == 4) i++;
                result[i]++;
                m--;
            }
            if(i == k - 1) result = {};
            else result[k-1] = m;
        }
        return result;
    }
}

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

    map<int, char> letters = {
        {1, 'a'},
        {2, 'c'},
        {3, 'g'},
        {4, 'o'}
    };

    ll n;
    cin >> n;

    string s;
    cin >> s;

    ll zero = 0, one = 0;
    for(ll i = 0; i < 8*n; i++){
        if(s[i] == '0') zero++;
        else one++;
    }
    zero -= n;
    one -= 2*n;

    //cout << zero << " " << one << "\n";
    vector<ll> chars = sum_up(one, n);
    /*for(ll i = 0; i < n; i++){
        cout << chars[i] << " ";
    }*/
    if(chars.size() == 0) cout << "NIE";
    else{
        string result;
        for(ll i = 0; i < n; i++){
            result += letters[chars[i]];
        }
        cout << result;
    }

    return 0;
}