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
#include <iostream>
#include <array>
#include <cstdio>
#include <limits>
using namespace std;

int main()
{
    int n;
    cin >> n;

    std::array<char, 8> arr{
        ';', ';', ';', 'a', 'c', 'g', 'w', ';'
    };
    int onesNumber = 0;
    cin.clear();
    fflush(stdin);
    for (int i=0;i<n*8;){
        int bit = std::getchar();
        if (bit == 49){
            onesNumber++;
            i++;
        }
        else if(bit==48){
            i++;
        }
    }
    if (onesNumber < 3*n || onesNumber >6*n){
        std::cout << "NIE" << std::endl;
        return 0;
    }
    int avg = onesNumber/n;
    int rest = onesNumber - (n*avg);

    int index=0;
    while(rest>0){
        int taken = std::min(6-avg, rest);
        rest -=taken;
        std::cout << arr[avg+taken];
        index++;
    }

    for (int i=index;i<n;i++){
        std::cout << arr[avg];
    }
    std::cout << std::endl;
    return 0;
}