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

using namespace std;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    string ciag;
    cin >> ciag;

    char asci[7]{};
    asci[3] = 'a'; asci[4] = 'c'; asci[5] = 'g'; asci[6] = 'o';

    int ile_jedynek{};
    string::size_type n_8 = ciag.size() + 1;

    for(string::size_type i =0; i < n_8; ++i)
    {
        if(ciag[i] == '1') ++ile_jedynek;
    }

    int baza = ile_jedynek / n;
    int modul = ile_jedynek % n;

    if(baza < 3 || baza > 6 || (baza == 6 && modul > 0) ) cout << "NIE";
    else{
        for(int i = 0; i < n; ++i)
        {
            if(modul > 0) 
            {
                cout << asci[baza+1];
                --modul;
            }else cout << asci[baza];
        }
    }

    return 0;
}