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
57
#include <iostream>
using namespace std;

int main()
{
    int n, amount[2] = { 0 };
    char bit;
    string sentence = "";
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int t = 0; t < 8; t++)
        {
            cin >> bit;
            amount[bit=='1']++;
        }
    }

    //Removing unnecessary bits (00111) for each 8bit sequence
    //011- repeats itself everywhere so we can remove it
    //after that, every letter a-z has at least one 0 and 1, so we remove them both
    amount[0] -= 2 * n;
    amount[1] -= 3 * n;

    //My pick of letters:
    //a - removes 000
    //c - removes 001
    //g - removes 011
    //o - removes 111

    while (amount[0] >= 3)
    {
        amount[0] -= 3;
        sentence += 'a';
    }
    while (amount[1] >= 3)
    {
        amount[1] -= 3;
        sentence += 'o';
    }
    if (amount[0] == 1)
    {
        amount[1] -= 2;
        sentence += 'g';
    }
    else if (amount[0] == 2)
    {
        amount[1] -= 1;
        sentence += 'c';
    }

    if (amount[1] == 0)
        cout << sentence;
    else
        cout << "NIE";
    return 0;
}