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
/*
 * zak.cpp
 *
 *  Created on: Dec 8, 2021
 *      Author: A.Mulawa
 */

#include <bits/stdc++.h>

using namespace std;

int main(int argc, char **argv)
{
    int l[] = {'a', 'c', 'g', 'w'};

    int n;
    scanf("%d", &n);
    char str[8 * 500000 + 1];
    scanf("%s", &str[0]);

    int lbr = 0;
    int ls = 0;
    int lw = 0;
    int km = 6;
    string s;
    do
    {
        lbr = 0;
        ls = 0;
        lw = 0;
        s = "";
        for (int i = 0; i < n; i++)
        {
            int lb = 0 + lbr;
            for (int j = 0; j < 8; j++)
            {
                if (str[i * 8 + j] == '1')
                {
                    lb++;
                    ls++;
                }
            }
            int t = max(3, min(lb, km));
            lbr = lb - t;
            s += char(l[t - 3]);
            lw += t;
        }
        km--;
    } while (ls != lw && km > 3);

    if (lbr < 0)
        cout << "NIE";
    else
        cout << s;

    //cout << "\n" << ls << " " << lw << " " << lbr << "\n" ;

    return 0;
};