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
//  Created by Michal Kowalski on 07/12/2021.
//

#include <iostream>
#include <vector>

int N;
char S[8*100000+10];

std::vector<int> find3456(int n1, int N) {
    int mod = n1 % 3;
    int n3 = (int)(n1 / 3);
    int n4 = 0;
    int n5 = 0;
    int n6 = 0;
    if (mod == 1 && n3 > 0) {
        // add 4
        ++n4;
        --n3;
    } else if (mod == 2 && n3 > 0) {
        // add 5
        ++n5;
        --n3;
    }
    int sum = n3 + n4 + n5 + n6;
    if (sum == N) {
        return {n3,n4,n5,n6};
    } else if (N > sum) {
        return {};
    } else {
        int diff = sum - N;
        int minus3 = diff * 2;
        if (minus3 > n3) return {};
        else {
            n3 -= minus3;
            n6 += diff;
        }
        /// search
        return {n3, n4, n5, n6};
    }
}

void print3456(std::vector<int> v) {
    if (v.size() == 0) {
        printf("NIE\n");
        return;
    }
    // 3 => a
    for (int i=0;i<v[0];++i) printf("a");
    // 4 => c
    for (int i=0;i<v[1];++i) printf("c");
    // 5 => g
    for (int i=0;i<v[2];++i) printf("g");
    // 6 => o
    for (int i=0;i<v[3];++i) printf("o");
    printf("\n");
}

int main() {
    scanf("%d",&N);
    scanf("%s",S);
    int n1 = 0;
    for (int i=0;i<8*N;++i) {
        if (S[i]== '1') ++n1;
    }
    std::vector v = find3456(n1, N);
    print3456(v);
    return 0;
}