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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    char letter[7];
    letter[3] = 'a';
    letter[4] = 'c';
    letter[5] = 'g';
    letter[6] = 'o';

    int n; cin >> n;
    string empty, s;
    getline(cin, empty);
    getline(cin, s);

    int j = 0;
    for (int i = 0; i < 8 * n; ++i) {
        j += s[i] == '1';
    }

    if (j > 6*n || j < 3*n) {
        cout << "NIE" << endl;
        return 0;
    }

    while (n > 0) {
        int v = j / n;
        cout << letter[v];
        j -= v;
        n--;
    }
    cout << endl;

    return 0;
}