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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>

using namespace std;

int main()
{

    /*for (int i = 1; i <= 26; i++)
    {
        int pos = 0;
        int neg = 0;
        for (int j = 0; j < 8; j++)
        {
            if ((i + 96) & (1 << j))
                pos++;
            else neg++;
        }
        cout << pos << ' ' << neg << '\n';
    }*/

    int n;
    cin >> n;
    string bits;
    cin >> bits;

    int pos = 0;
    int neg = 0;
    for (auto it : bits)
    {
        if (it == '1')
            pos++;
        else
            neg++;
    }
    //cout << pos << ' ' << neg << '\n';

    int startPos = 3 * n;
    int startNeg = 5 * n;
    int changesA = pos - startPos;
    int changesB = startNeg - neg;

    if (changesA != changesB || changesA < 0 || changesA > n * 3)
    {
        cout << "NIE\n";
        return 0;
    }

    int changes = changesA;

    for (int i = 0; i < n; i++)
    {
        if (changes >= 3)
        {
            cout << 'w';
            changes -= 3;
        }
        else if (changes >= 2)
        {
            cout << 'g';
            changes -= 2;
        }
        else if (changes >= 1)
        {
            cout << 'c';
            changes--;
        }
        else
        {
            cout << 'a';
        }
    }


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

}