1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <cstdio>        // Ignacy Boehlke
using namespace std;     // XIII LO Szczecin

int main() {
    int n, c = 0;
    scanf("%d ", &n);
    for (int i = 0; i < 8 * n; ++i) c += (getchar() == '1');
    auto chk = [&](int a, int b) {return (a >= b * 3 && a <= b * 6);};
    if (!chk(c, n)) puts("NIE");
    else {
        while (n) {
            if (chk(c - 3, n - 1)) putchar('a'), c -= 3;
            else if (chk(c - 4, n - 1)) putchar('c'), c -= 4;
            else if (chk(c - 5, n - 1)) putchar('g'), c -= 5;
            else putchar('o'), c -= 6;
            --n;
        }
        putchar('\n');
    }
}