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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int num_of_letters;
    cin >> num_of_letters;
    int ones = 0;
    for (int i = 0; i < num_of_letters * 8; i++)
    {
        char a;
        cin >> a;
        if (a == '1')
            ones++;
    }
    if (ones < num_of_letters * 3 or ones > num_of_letters * 6)
    {
        cout << "NIE";
    }
    else
    {
        string message = "";
        ones -= num_of_letters * 3;
        int num_of_o = 0;
        int num_of_g = 0;
        int num_of_c = 0;
        int num_of_a = 0;
        while (ones > 2)
        {
            ones -= 3;
            num_of_o++;
            message += "o";
        }
        if (ones == 2)
        {
            ones -= 2;
            num_of_g++;
            message += "g";
        }
        if (ones == 1)
        {
            ones -= 1;
            num_of_c++;
            message += "c";
        }
        num_of_a = num_of_letters - num_of_o - num_of_g - num_of_c;

        for (int i = 0; i < num_of_a; i++)
        {
            message += "a";
        }
        cout << message;
    }
    return 0;
}