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

using namespace std;

char tab[] = {'0', '1', '2', 'a', 'c', 'g', 'o'};

int main()
{
  int n;
  int sum = 0;
  char c;
  cin >> n;
  for(int i = 0; i < 8*n; i++) {
    cin >> c;
    if(c == '1')
      sum++;
  }
  if (sum > 6*n || sum < 3*n) {
    cout << "NIE" << endl;
    return 0;
  }

  int lower_char = sum / n;
  int upper_char_num = sum % n;

  for (int i = 0; i < upper_char_num; i++) {
    cout << tab[lower_char+1];
  }

  for (int i = 0; i < n-upper_char_num; i++) {
    cout << tab[lower_char];
  }

  cout << endl;

  return 0;
}