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
#include <algorithm>
#include <iostream>
#include <string>

int main(void) {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  int count = 0;
  for (char c: s) {
    if (c == '1') {
      count++;
    }
  }
  std::string result;
  if ((count < 3 * n) || (count > 6 * n)) {
    result = "NIE";
  } else {
    count -= 3 * n;
    const uint8_t mapping[] = {0b0000, 0b0010, 0b0110, 0b1110};
    for (int i = 0; i < n; i++) {
      int extra_bits = std::min(count, 3);
      count -= extra_bits;
      result += 'a' | mapping[extra_bits];
    }
  }
  std::cout << result << std::endl;
  return 0;
}