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

struct Count {
    int zeros{0};
    int ones{0};
};

std::string solution(Count c, int n) {
    c.ones -= 2*n;
    c.zeros -= n;

    if(c.zeros < 0 || c.ones < 0) {
        return "NIE";
    }

    if((c.ones + c.zeros) % 5 != 0) {
        return "NIE";
    }

    int min = std::min(c.ones, c.zeros);
    int max = std::max(c.ones, c.zeros);
    if(min*4 < max) {
        return "NIE";
    }

    std::string res = "";
    while(c.ones != 0 && c.zeros != 0) {
        if(c.zeros == c.ones) {
            res += "ao";
            c.zeros -= 5;
            c.ones -= 5;
            continue;
        }
        if(c.zeros < c.ones) {
            if(c.ones >= 4) {
                res += "o";
                c.zeros -= 1;
                c.ones -= 4;
            } else {
                res += "g";
                c.zeros -= 2;
                c.ones -= 3;
            }
        } else {
            if(c.zeros >= 4) {
                res += "a";
                c.zeros -= 4;
                c.ones -= 1;
            } else {
                res += "c";
                c.zeros -= 3;
                c.ones -= 2;
            }
        }
    }

    return res;
}

int main()
{
    int n, n_;
    Count count;

    std::cin >> n;
    n_ = 8*n;
    while(n_--) {
        char b;
        std::cin >> b;
        if(b == '0') {
            ++count.zeros;
        } else {
            ++count.ones;
        }
    }

    std::cout << solution(count, n) << '\n';

    return 0;
}