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
46
47
48
49
50
51
52
53
54
55
56
57
58
//
//  main.cpp
//  zak
//
//  Created by Wojciech Siwko on 08/12/2021.
//

#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int pow(int in) {
    if (in == 0) return 1;
    else return 2 * pow(in - 1);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<char> in(8*n);
    vector<int> out_bytes(n);
    vector<char> m = {'a', 'c', 'g', 'o'};
    int ones = 0;
    for (int i = 0; i < 8*n; i++) {
        cin >> in[i];
        if (in[i] == '1') ones++;
    }
    if (ones >= 3*n && ones <= 6*n) {
        ones -= 2*n;
        int spread = ones / n;
        int rest = ones - spread*n;
        for (int i = 0; i < n; i++) {
            out_bytes[i] += spread;
        }
        for (int i = 0; i < n; i++) {
            if (rest - (4 - out_bytes[i]) >= 0) {
                rest -= 4 - out_bytes[i];
                out_bytes[i] = 4;
            }
            else {
                out_bytes[i] += rest;
                rest = 0;
                break;
            }
        }
        for (int i = 0; i < out_bytes.size(); i++) {
            cout << m[out_bytes[i] - 1];
        }
        cout << endl;
    }
    else {
        cout << "NIE" << endl;
    }
    return 0;
}