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
#include <iostream>
#include <stdio.h>
using namespace std;

string tab[10];

int main(){

        int n;
        string s;       
        cin >> n >> s;

        tab[3] = "a";
        tab[4] = "c";
        tab[5] = "g";
        tab[6] = "o";
        
        int ones = 0;
        for(int i=0; i<s.size(); i++){
            if(s[i] == '1') ones++;
        }

        if(ones < 3*n) cout << "NIE" << endl;
        else if (ones > 6*n) cout << "NIE" << endl;
        else {
            int avg = ones/n;
            int rem = ones - n*avg;
            string res = "";

            for(int i=0; i<rem; i++){
                res += tab[avg+1];
            }
            for(int i=0; i<n-rem; i++){
                res += tab[avg];
            }
            cout << res << endl;           
        }
}