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
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
bool check(int n, int one)
{
    return 2*n <= one && one <= 5*n;
}
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int one = 0;
    for (int i=0;i<size(s);i++)
        if (s[i]=='0') one++;
    
    if (check(n, one))
    {
        vector<char> C = {'0', '0', 'w', 'g', 'c', 'a'};
        for (int i=2;i<6;i++)
        {
            while (n>0 && check(n-1, one - i))
            {
                one-=i;
                n--;
                cout << C[i];
            }
        }
    }
    else
        cout << "NIE";
    cout << '\n';
    
}