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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    int s = 0;
    char c;
    cin.get(c);
    for (int i = 0; i < 8 * n; i++) {
        cin.get(c);
        if (c == '1') {
            s++;
        }
    }

    map<int, char> m = {
        {3, 'a'},
        {4, 'c'},
        {5, 'g'},
        {6, 'o'},
    };

    // cout << "s: " << s << endl;

    if (s >= 3 * n && s <= 6 * n) {
        int base = s / n;
        int rem = s % n;
        // cout << "base: " << base << "; rem: " << rem << endl;
        for (int i = 0; i < rem; i++) {
            putchar(m[base + 1]);
        }
        for (int i = 0; i < n - rem; i++) {
            putchar(m[base]);
        }
        putchar('\n');
    } else {
        cout << "NIE" << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    solve();
    return 0;
}