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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    
    int n;
    char c;
    int ones_total = 0;
    char samples[] = { 'a', 'c', 'g', 'o', '\0' };

    cin >> n;

    for (int i = 0; i < 8 * n; i++) {
        cin >> c;

        if (c == '1') {
            ones_total++;
        }
    }

    if (ones_total < 3 * n || ones_total > 6 * n) {
        cout << "NIE";
    }
    else {
        int base_char_index = ones_total / n - 3;

        char base_char = samples[base_char_index];
        char support_char = samples[base_char_index + 1];
        int support_chars_count = ones_total % n;
        int base_chars_count = n - support_chars_count;

        for (int i = 0; i < base_chars_count; i++) {
            cout << base_char;
        }
        for (int i = 0; i < support_chars_count; i++) {
            cout << support_char;
        }
    }

	return 0;
}