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
#include <cstdio>
#include <vector>

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

int main() {
    int N;
    int ones = 0;
    std::vector<char> data;
    std::vector<char> result;

    scanf("%d", &N);
    data.resize(8*N+10);
    scanf("%s", &data[0]);

    for (int i=0; i<8*N; ++i) {
        ones += (data[i] == '1');
    }

    if (ones < 3*N || ones > 6*N) {
        printf("NIE\n");
        return 0;
    }

    for (int size=N; size>0; --size) {
        int use = ones - (size-1) * 3;
        if (use>=6) {
            result.push_back('o');
            ones -= 6;
        } else if (use>=5) {
            result.push_back('g');
            ones -= 5;
        } else if (use>=4) {
            result.push_back('c');
            ones -= 4;
        } else {
            result.push_back('a');
            ones -= 3;
        }
    }

    result.push_back(0);
    printf("%s\n", &result[0]);

    return 0;
}