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
#include <iostream>
using namespace std;

// + 3
char ch[4] = { 'a', 'c', 'g', 'o' };

int res[100000];

int n, jed;
char b;

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

    cin >> n;
    for (int i = 0; i < n * 8; ++i) {
        cin >> b;
        if (b == '1') ++jed;
    }

    jed -= n * 3;

    if (jed < 0) {
        cout << "NIE";
        return 0;
    }

    for (int i = 0; i < n; ++i) {
        res[i] = min(3, jed);
        jed -= res[i];
        if (jed == 0) break;
    }

    if (jed > 0) {
        cout << "NIE";
        return 0;
    }

    for (int i = 0; i < n; ++i) cout << ch[res[i]];
}