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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    char c, tab[7] = { '\0', '\0', '\0', 'a', 'c', 'g', 'o' };
    string msg = "";
    int n, ones = 0, zeros, avg, ones_c, zeros_c, n_c;
    cin >> n;
    for (int i = 0; i < 8*n; ++i) {
        cin >> c;
        if (c == '1') ones++;
    }
    zeros = 8*n - ones;
    ones_c = ones;
    zeros_c = zeros;
    n_c = n;
    while (true) {
        if (ones_c <= 0) break;
        avg = ones_c / n_c;
        if (avg < 3 || avg > 6) {
            cout << "NIE";
            return 0;
        }
        ones_c -= avg;
        zeros_c -= (8-avg);
        msg += tab[avg];
        n_c--;
    }
    if (ones_c == 0 && zeros_c == 0) {
        cout << msg;
        return 0;
    }
    ones_c = ones;
    zeros_c = zeros;
    msg = "";
    n_c = n;
    while (true) {
        if (zeros_c <= 0) break;
        avg = zeros_c / n_c;
        if (avg < 2 || avg > 5) {
            cout << "NIE";
            return 0;
        }
        zeros_c -= avg;
        ones_c -= (8-avg);
        msg += tab[8-avg];
        n_c--;
    }
    if (ones_c == 0 && zeros_c == 0) cout << msg;
    else cout << "NIE";

    return 0;
}