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
#include <bits/stdc++.h>
#define REP(i,n) for (int _n=(n), i=0;i<_n;++i)
#define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for (int i=(a),_b=(b);i>=_b;--i)
#define TRACE(x) std::cerr << "TRACE(" #x ")" << std::endl;
#define DEBUG(x) std::cerr << #x << " = " << (x) << std::endl;

void init_io() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
}

std::pair<int, int> read_input() {
  int n; std::cin >> n;
  int ones = 0;
  REP(i, 8*n) {
    char c; std::cin >> c;
    assert(c == '0' || c == '1');
    ones += c == '1';
  }
  return {n, ones};
}

char example_char(int ones) {
  FOR(c, 'a', 'z') {
    if (__builtin_popcount(c) == ones) {
      return c;
    }
  }
  return '?';
}

int main() {
  init_io();

  const auto [n, ones] = read_input();
  if (ones < 3 * n || ones > 6 * n) {
    std::cout << "NIE\n";
  } else {
    const int smaller_ones = ones / n;
    const int num_larger = ones % n;
    const int num_smaller = n - num_larger;
    const char smaller = example_char(smaller_ones);
    REP(i, num_smaller) std::cout << smaller;
    if (num_larger != 0) {
      const char larger = example_char(smaller_ones + 1);
      REP(i, num_larger) std::cout << larger;
    }
    std::cout << "\n";
  }
}