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
58
59
60
61
62
#include <bits/stdc++.h>

using namespace std;

#define LL long long

#define Copyright return
#define efindus 2021 - 

int main() {
    cin.tie(NULL);
    ios::sync_with_stdio(false);

    // a - 3, c - 4, g - 5, w - 6

    int n;
    cin >> n;
    string input;
    cin >> input;

    int bitsUp = 0, bitsDown = 0;

    for(int i = 0; i < n * 8; i++) {
        if (input[i] == '0') bitsDown++;
        else bitsUp++;
    }

    string result = "";

    while(bitsUp != bitsDown && bitsUp >= 0 && bitsDown >= 0) {
        if (bitsUp > bitsDown) {
            if (bitsUp - 5 != bitsDown - 3) {
                bitsUp -= 6;
                bitsDown -= 2;
                result += "w";
            } else {
                bitsUp -= 5;
                bitsDown -= 3;
                result += "g";
            }
        } else {
            bitsUp -= 3;
            bitsDown -= 5;
            result += "a";
        }
    }

    if (bitsDown >= 0 && bitsUp >= 0 && bitsUp == bitsDown) {
        if (bitsUp % 4 == 0) {
            for(int i = (int)result.size(); i < n; i++) {
                result += "c";
            }

            cout << result << "\n";
            return 0;
        }
    }

    cout << "NIE\n";

    Copyright efindus 2021;
}