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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
char tab[7];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i;
    tab[3] = 'a';
    tab[4] = 'c';
    tab[5] = 'g';
    tab[6] = 'o';
    int n;
    cin>>n;
    string s;
    cin>>s;
    int suma = 0;
    for (char c : s) suma += (c=='1');
    if (suma < 3*n || suma > 6*n){
        cout<<"NIE\n";
        return 0;
    }
    for (i = 0; i < n; i++){
        for (int j = 6; j > 2; j--){
            if (suma-j >= 3*(n-i-1)){
                cout<<tab[j];
                suma -= j;
                break;
            }
        }
    }
    cout<<"\n";
    return 0;
}