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
#include <cstdio>

const int MIN_ONES = 3;
const int MAX_ONES = 6;

const char ONES[7] = { 0, 0, 0, 'a', 'c', 'g', 'o' };

int main()
{
    int n;
    scanf("%d\n", &n);
    int b = 8 * n;
    int ones = 0;
    while (b-- > 0) {
        ones += (getchar() == '1');
    }

    if (ones < MIN_ONES * n || ones > MAX_ONES * n) {
        puts("NIE");
        return 0;
    }
    int min_ones = ones / n;
    int up_ones = ones % n;

    for (int i=0; i<n; ++i) {
        putchar(ONES[min_ones + (up_ones-- > 0)]);
    }
    putchar('\n');
}