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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    char chosen_letter[8] = {};
    for (char letter = 'a'; letter <= 'z'; ++letter) {
        int bits = 0;
        for (int i = 0; i < 8; ++i) {
            bits += (letter >> i) & 1;
        }
        if (!chosen_letter[bits]) {
            chosen_letter[bits] = letter;
        }
    }
    int n;
    string bits;
    cin >> n >> bits;
    int ones = 0;
    for (char bit: bits) {
        ones += bit == '1';
    }
    if (ones < 3 * n || 6 * n < ones) {
        cout << "NIE" << endl;
        return 0;
    }
    int ones_per_letter = ones / n;
    int add_one = ones % n;
    for (int i = 0; i < n; ++i) {
        if (add_one > 0) {
            cout << chosen_letter[ones_per_letter + 1];
            --add_one;
        } else {
            cout << chosen_letter[ones_per_letter];
        }
    }
    cout << endl;
    return 0;
}