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

using namespace std;

const int MAX_N=100007;
int Num[5], DP[MAX_N], NIGGER[MAX_N];
char qq;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie();



    long long kwota, n, lol;

    Num[0]=3;
    Num[1]=4;
    Num[2]=5;
    Num[3]=6;
    n = 4;

    kwota = 100007;

            for(int i=1; i<=kwota; i++)
                {
                    int wynik = -1;
                    for(int j=0; j<n; j++)
                    {
                        int nominal = Num[j];
                        if(nominal>i || DP[i-nominal]==-1)
                        {
                            continue;
                        }
                        int akt = 1+DP[i-nominal];

                        if(akt<wynik || wynik==-1)
                        {
                            wynik=akt;
                            NIGGER[i]=nominal;
                        }
                    }
                    DP[i]=wynik;
                }


    //cin>>sheesh;

    long long u, dd;

   // for(long long f=0; f<sheesh; f++)
    //{
        kwota = 0;
        cin>>lol;
        for(long long heil=0; heil<lol*8; heil++)
        {
            qq = getchar();
            if(qq == '1')
            {
                kwota++;
            }

        }
            //kwota - suma

        u=kwota;


        dd = 0;
            if(DP[kwota]<lol)
            {
                dd = lol - DP[kwota];
            }

        if(kwota<lol*3 or kwota>6*lol)
        {
            cout << "NIE";
        }
        else
        {
            while(NIGGER[u]!=0)
            {
                switch(NIGGER[u])
                {
                case 3:
                    cout<<'a';
                    break;
                case 4:
                    cout<<'f';
                    break;
                case 5:
                    cout<<'g';
                    break;
                case 6:
                    if(dd>0)
                    {
                        cout<<'a'<<'a';
                        dd--;
                    }
                    else
                    {
                        cout<<'o';
                    }
                    break;
                }
                u -= NIGGER[u];
            }
        }
        kwota = 0;
    //}


    return 0;
}