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
#include<bits/stdc++.h>
using namespace std;

// 3 a
// 4 c
// 5 g
// 6 o

string ans="NIE";

void  f(int n,int l, int j,string odp)
{
   if(j<0 || l>n)
   {
       return;
   }
   if(l==n && j==0)
   {
    ans=odp;
    return ;
   }
   f(n,l+1,j-3,odp+"a");
   f(n,l+1,j-4,odp+"c");
   f(n,l+1,j-5,odp+"g");
   f(n,l+1,j-6,odp+"o");
}

int main()
{
    int n;
    cin >> n;
    int j=0; // jeden
    for(int i=0; i<n*8; i++)
    {
        char x;
        cin >> x;
        if(x=='1')
        {
            j++;
        }
    }
    f(n,0,j,"");
   cout << ans;
}