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
#include<bits/stdc++.h>
using namespace std;
int litery[4];
int main(){
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ile=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            ile++;
        }    
    }
    //cout<<ile<<"\n";
    if(ile<3*n||ile>6*n){
        cout<<"NIE";
        return 0;
    }    
    litery[0]=n;
    int d=ile-3*n;
    int x=d%3;
    int y=d/3;
    litery[0]-=y;
    litery[3]+=y;
    if(x==1){
        litery[1]=1;
        litery[0]--;
    }
    if(x==2){
        litery[2]=1;
        litery[0]--;
    }
    for(int i=0;i<4;i++){
        while(litery[i]>0){
            if(i==0){
                cout<<'a';
            }
            if(i==1){
                cout<<'c';
            }
            if(i==2){
                cout<<'g';
            }
            if(i==3){
                cout<<'o';
            }
            litery[i]--;
        }
    }
    return 0;
}