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
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <bits/stdc++.h>

using namespace std;

int l[2];
int main()
{
    int n;
        string s="";
    /*srand(time(NULL));

    for(int i=0;i<15;++i){
        int n;
        string s="";
        int a,b2,c,d;
      //   a=398;b2= 182;c= 232;d= 28;
      //a=287;b2= 332;c= 219;d= 378;

        a=rand()%500;
        b2=rand()%500;
        c=rand()%500;
        d=rand()%500;

    cout<<a<<' '<<b2<<' '<<c<<' '<<d<<endl;
    n=a+b2+c+d;
        for(int i=0;i<a;++i){
            s+="111";
        }
        for(int i=0;i<a;++i){
            s+="00000";
        }
        for(int i=0;i<b2;++i){
            s+="0000";
        }
        for(int i=0;i<b2;++i){
            s+="1111";
        }
        for(int i=0;i<c;++i){
            s+="11111";
        }
        for(int i=0;i<c;++i){
            s+="000";
        }
        for(int i=0;i<d;++i){
            s+="008";
        }
        for(int i=0;i<d;++i){
            s+="111111";
        }
        //s+="00000000";
//398 182 232 28
*/
    ios_base::sync_with_stdio(false);
    //cout<<s<<endl;
   cin>>n>>s;
   for(int i=0;i<s.size();++i){
			l[(char)s[i]-48]++;
		}
	//cin>>n>>l[0]>>l[1];
	//cout<<l[0]<<' '<<l[1]<<endl;
	bool b=1;
	string w="";
	while(b){
			b=0;
			if(l[0]%5==0&&l[1]%3==0&&(l[0]/5)*3==l[1]){
                while(l[0]>0){
					l[0]-=5;
					l[1]-=3;
					w+="a";
					}
			}
			if(l[1]%5==0&&l[0]%3==0&&(l[1]/5)*3==l[0]){
                while(l[0]>0){
					l[0]-=3;
					l[1]-=5;
					w+="g";
					}
			}
			if(l[1]%6==0&&l[0]%2==0&&(l[1]/6)*2==l[0]){
                while(l[0]>0){
					l[0]-=2;
					l[1]-=6;
					w+="o";
					}
			}
			if(l[1]-l[0]>=3&&l[0]-2>=0&&l[1]-6>=0){
				l[0]-=2;
				l[1]-=6;
				w+="o";
				b=1;
				}
			if(l[0]%4==0&&l[1]%4==0&&l[0]==l[1]){
				while(l[0]>0){
					l[0]-=4;
					l[1]-=4;
					w+="c";
					}
				}
			if(l[0]-l[1]==2&&l[0]-5>=0&&l[1]-3>=0){ //l[0]>=5&&l[1]>=3&&l
				l[0]-=5;
				l[1]-=3;
				w+="a";
				b=1;

				}
			if(l[0]==l[1]&&l[0]-4>=0){
				l[0]-=4;
				l[1]-=4;
				w+="c";
				b=1;
			}
			if(l[1]-l[0]==2&&l[0]-3>=0&&l[1]-5>=0){
				l[0]-=3;
				l[1]-=5;
				w+="g";;
				b=1;
			}
			else if(l[1]<l[0]&&l[1]-3>0&&l[0]-5>0){
                while(l[1]<l[0]&&l[1]-3>0&&l[0]-5>0){
                    l[1]-=3;
                    l[0]-=5;
                    w+="a";
                }
                b=1;
			}
                //cout<<l[0]<<' '<<l[1]<<endl;
		}
//cout<<w.size();
    if(w.size()!=n||(l[0]!=0||l[1]!=0)){

			cout<<"NIE";
		}
	else
	cout<<w;
//l[0]=0;
//l[1]=0;

   // }

    return 0;
}
//2 0000011111111111