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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define MAXN 100001

using namespace std;

char D[10];
int C[10];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    D[3] = 'a';
    D[4] = 'c';
    D[5] = 'g';
    D[6] = 'o';

    C[3] = 0;
    C[4] = 0;
    C[5] = 0;
    C[6] = 0;

    int n;
    cin >> n;

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

    bool ok = true;

    if (ones >= 3 * n && ones < 4 * n) {
        C[4] = ones - 3 * n;
        C[3] = n - C[4];
    } else if (ones >= 4 * n && ones < 5 * n) {
        C[5] = ones - 4 * n;
        C[4] = n - C[5];
    } else if (ones >= 5 * n && ones <= 6 * n) {
        C[6] = ones - 5 * n;
        C[5] = n - C[6];
    } else {
        ok = false;
    }

    if (!ok) {
        cout << "NIE";
    } else {
        for (int x = 3; x <= 6; x++) {
            for (int i = 0; i < C[x]; i++)
                cout << D[x];
        }
    }

    cout << endl;

    return 0;
}