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

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);

    char chars[4] = {'a', 'c', 'g', 'o'};

    int n;
    std::cin >> n;
    int count = 0;

    for (auto i = 0; i < n * 8; i++) {
        char c;
        std::cin >> c;
        if (c == '1') count++;
    }

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

    int rest = count - n * 3;
    std::vector<int> nums(n, 0);

    for (auto i = 0; i < n; i++) {
        if (rest == 0) break;
        int addition = std::min(3, rest);
        rest -= addition;
        nums[i] += addition;
    }

    for (auto i = 0; i < n; i++) std::cout << chars[nums[i]];
    std::cout << std::endl;

    return 0;
}