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
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define vc vector
#define mt make_tuple
int main()
{
    int n,counter_1=0,counter_0=0;
    cin>>n;
    string bin;
    cin>>bin;
    for(char x : bin)
    {
        if(x=='0')
        {
            counter_0++;
        }
        else
        {
            counter_1++;
        }
    }
    if(counter_1>counter_0*3 || counter_0*3>counter_1*5 || (counter_0-counter_1)%2==1)
    {
        cout<<"NIE";
    }
    else
    {
       string wynik ="";
       while(counter_0>0 || counter_1>0)
       {
           if(counter_0>=counter_1+2)
           {
               wynik.push_back('a');
               counter_0-=5;
               counter_1-=3;
           }
           else if(counter_0==counter_1)
           {
               wynik.push_back('c');
               counter_0-=4;
               counter_1-=4;
           }
           else if(counter_1==counter_0+2)
           {
               wynik.push_back('m');
               counter_0-=3;
               counter_1-=5;
           }
           else
           {
               wynik.push_back('w');
               counter_0-=2;
               counter_1-=6;
           }
       }
       cout<<wynik;
    }
}