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

using namespace std;

int count_ones (char c) {
    int cnt = 0;
    for (int i = 0; i<8; ++i)
        cnt += c & (1 << i) ? 1 : 0;
    return cnt;
}

void rep (char c, int k) {
    for (int i=0; i<k; ++i)
        cout << c;
}

int main() {

/*
    for (char c = 'a'; c <= 'z'; ++c)
        cout << c << " " << 2*count_ones(c) - 8 << endl;
*/

    int n;
    cin >> n;

    int num[2] = {0,0};

    for (int i=0; i<8*n; ++i) {
        char c;
        cin >> c;
        num [c - '0']++;
    }

    int diff = abs(num[0] - num[1]);
    if (diff % 2 == 1)
        cout << "NIE";
    else
        if (num[1] >= num[0]) {
            if (diff <= 4*n) {
                rep('o', diff / 4);
                n -= diff / 4;
                if (diff % 4 > 0) {
                    cout << 'g';
                    --n;
                }
                rep ('c', n);
            }
            else
                cout << "NIE";
        }
        else {
            if (diff <= 2*n) {
                rep('a', diff / 2);
                n -= diff / 2;
                rep ('c', n);
            }
            else
                cout << "NIE";
        }

    return 0;
}