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

int main() {
  vector<pair<int, char>> els = {{3, 'a'}, {4, 'c'}, {5, 'g'}, {6, 'o'}};

  int n; scanf("%d", &n);
  int a = 0;
  for (int i=0; i<n*8; ++i) {
    char v; scanf(" %c", &v);
    if (v == '1') {
      ++a;
    }
  }

  if ((n * els.begin()->first > a) ||
      (n * els.rbegin()->first < a)) {
    printf("NIE\n");
    return 0;
  }

  for (auto el : els) {
    while (n > 0 && (n-1) * els.rbegin()->first >= a - el.first) {
      printf("%c", el.second);
      a -= el.first;
      --n;
    }
  }

  printf("\n");
  return 0;
}