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
#include<iostream>
#include<vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    string a;
    cin >> n >> a;
    int j = 0, m = n;
    for (int i = 0; i < 8*n; i++)
        j += a[i] - '0';
    vector<char> res;
    static const char t[] = {'a', 'c', 'g', 'o'};
    for (int i = 3; i < 7; i++) {
        while (m > 0 && i * m <= j && (i + 1) * m > j) {
            j-=i;
            m-=1;
            res.push_back(t[i - 3]);
        }
    }
    if (j > 0 || m != 0) {
        cout << "NIE";
        return 0;
    }
    for (auto c : res)
        cout << c;
}