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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nd second
#define st first
#define mp make_pair
char wynik, a;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, wyn=0, sumka=0;
    cin>>n;

    for(int i=0;i<n*8;i++)
    {
        cin>>a;
        if(a=='1') wyn++;
    }
    if(wyn<3){
        cout<<"NIE";
        return 0;
    }
    int ile3=0, ile6=0;
    if(wyn%3==0) ile3=wyn/3;
    else
    {
        ile3=wyn/3-1;
        wyn=wyn%3+3;
        if(wyn==4) wynik='c';
        else wynik='g';
        sumka+=1;
    }
    ile6=(sumka+ile3)-n;
    ile3-=ile6*2;
   // cout<<ile3<<" "<<ile6<<"\n";
    if(ile3<0||ile6<0)
    {
        cout<<"NIE";
        return 0;
    }
    for(int i=0;i<ile3;i++)
    {
        cout<<'a';
    }
    for(int i=0;i<ile6;i++)
    {
        cout<<'w';
    }
    if(wynik=='c') cout<<'c';
    if(wynik=='g') cout<<'g';
}