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
#include <iostream>
using namespace std;

char having(int bits) {
    return 96 + (1 << (bits - 2)) - 1;
}

int main() {
    ios::sync_with_stdio(false); cin.tie();
    int n; cin >> n;
    string s; cin >> s;
    int ones = 0;
    for (char c : s) {
        if (c == '1') ones++;
    }

    int lo = 3 * n;
    int hi = 6 * n;

    if (lo <= ones && ones <= hi) {
        int extra = ones - lo;
        int six = extra / 3;
        int trans = extra % 3;
        for (int i = 0; i < six; i++) {
            cout << having(6);
        }
        if (trans) cout << having(3 + trans);
        for (int i = six + !!trans; i < n; i++) {
            cout << having(3);
        }
        cout << '\n';
    } else {
        cout << "NIE\n";
    }
}