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
#include <bits/stdc++.h>
using namespace std;

/*
ascii chars popcnt
3/5 - a
4/4 - c
5/3 - g
6/2 - o

6 2 + 3 5 ? -> 9 7 d2
-> ao 2char diff 9 7 -> 4 4 + 5 2 ca ok
*/

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin>>n;

    int one_cnt = 0, zero_cnt = 0;
    for(int i=0; i<8*n; i++) {
        char c;
        cin>>c;
        if(c == '1')
            one_cnt++;
        else
            zero_cnt++;
    }
   // cout<<one_cnt<<' '<<zero_cnt<<'\n';
    int diff = one_cnt-zero_cnt;
    if(diff < 0) {
        int diffc = diff/2; 
        one_cnt -= 3*diffc;
        zero_cnt -= 5*diffc;

        if(one_cnt % 4 != 0 || zero_cnt % 4 != 0 || one_cnt/4 != zero_cnt/4 || diff % 2 != 0) {
            cout<<"NIE\n";
            return 0;
        }
        for(int i=0; i<diffc; i++)
            cout<<'a';
        for(int i=0; i<one_cnt/4; i++)
            cout<<'c';
        cout<<'\n';
    } else if (diff > 0) {
        int diffc = diff/2;
        // change gg for oc -> diff const; n1 0; n0 0 -> not neccessary
        one_cnt -= 5*diffc;
        zero_cnt -= 3*diffc;
        if(one_cnt % 4 != 0 || zero_cnt % 4 != 0 || one_cnt/4 != zero_cnt/4 || diff % 2 != 0) {
            cout<<"NIE\n";
            return 0;
        }
        for(int i=0; i<diffc; i++)
            cout<<'g';
        for(int i=0; i<one_cnt/4; i++)
            cout<<'c';
        cout<<'\n';
    } else {
        if(one_cnt % 4 != 0 || zero_cnt % 4 != 0 || one_cnt/4 != zero_cnt/4 || one_cnt/4 != n) {
            cout<<"NIE\n";
            return 0;
        }
        for(int i=0; i<one_cnt/4; i++)
            cout<<'c';
        cout<<'\n';
    }
}