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

using namespace std;
vector<int> vec;
vector<char> word;
int n{0};
int nn{0};
int m{0};
char w{0};
int sum{0};
int sumK{1};
const int ASC=8;
int sum1{0};
int sumvec1{0};

int main() {
    cin>>nn;
    n=nn;
    m=4;
    for(int i=0;i<n*ASC;i++){
        cin>>w;
        word.push_back(w);
    }
    for(int i=0;i<word.size();i++){
        if(word[i]=='1'){
            sum1+=1;
        }
    }
            struct Generator {
            public:
                Generator(int n, int m)
                        : cSlots(n), cValues(m) {
                    a = new int[n];

                    for (int i = 0; i < cSlots - 1; i++) {
                        a[i] = 1;
                    }
                    a[cSlots - 1] = 0;

                    nextInd = cSlots;
                }

                ~Generator() {
                    delete a;
                }

                bool doNext() {
                    for (;;) {
                        if (a[nextInd - 1] == cValues) {
                            nextInd--;
                            if (nextInd == 0)
                                return false;
                        } else {
                            a[nextInd - 1]++;
                            while (nextInd < cSlots) {
                                nextInd++;
                                a[nextInd - 1] = 1;
                            }

                            return true;
                        }
                    }
                }
                void doPrint() {
                    for (int i = 0; i < cSlots; i++) {
                        vec.push_back(a[i]);
                    }
                    for (int i = 0; i < vec.size(); i++) {
                        if (vec[i] == 1) {
                            sumvec1 += 3;
                        }
                        if (vec[i] == 2) {
                            sumvec1 += 4;
                        }
                        if (vec[i] == 3) {
                            sumvec1 += 5;
                        }
                        if (vec[i] == 4) {
                            sumvec1 += 6;
                        }
                    }
                    if (sumvec1 == sum1) {
                        sum+=1;
                        sumK=0;
                        for (int i = 0; i < vec.size(); i++) {
                            if (vec[i] == 1) {
                                cout << "a";
                            }
                            if (vec[i] == 2) {
                                cout << "c";
                            }
                            if (vec[i] == 3) {
                                cout << "g";
                            }
                            if (vec[i] == 4) {
                                cout << "o";
                            }
                        }
                    }
                        vec.clear();
                        sumvec1 = 0;
                    }
            private:
                int *a;
                int cSlots;
                int cValues;
                int nextInd;
            };

            Generator g(n, m);
            while (g.doNext()) {
                if(sum==0){
                    g.doPrint();
                }
                else{
                    break;
                }
            }
            if(sumK!=0){
                cout<<"NIE";
            }
    return 0;
}