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
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#define MAX 100009

char result[MAX];

int main()
{
    int bitCount;
    std::string input;
    
    std::cin >> bitCount >> input;
    
    int onesCount = 0;
    
    for (char &bit : input) {
        if (bit == '1') onesCount += 1;
    }
    
    // First 3 are empty as there are no letters that uses such ones count
    char letter[] = {'-', '-', '-', 'a', 'c', 'g', 'o'};
    
    int nextId = 0;
    
    while (bitCount) {
        int avg = onesCount / bitCount;
        
        if (avg < 3 || avg > 6) {
            std::cout << "NIE";
            return 0;
        }
        
        result[nextId++] = letter[avg];
        onesCount -= avg;
        
        bitCount -= 1;
    }
    
    for (int i=0; i<nextId; i++) std::cout << result[i];
}