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
#include <stdio.h>

int main() {
  int i, n;
  char s, s3 = 'a', s4 = 'c', s5 = 'g', s6 = 'o';
  scanf("%d", &n);
  int la = n*8, l0 = 0, l1 = 0;

  for(int i = 0; i < la; i++) {
    scanf(" %c", &s);
    if (s == '1') { l1++; } else { l0++; }
  }

//  printf("\n\nla=%d, l0=%d, l1=%d\n\n", la, l0, l1);

  if ((l1*5 < l0*3) || (l1*2 > l0*6)) {
    printf("NIE");
    return 0;
  }
  while(l1 != 0) {
    if(l1 < l0) {
      l1 -= 3; l0 -= 5;
      printf("a");
    } else if(l1 == l0) {
      l1 -= 4; l0 -= 4;
      printf("c");
    } else if(l1-3 > l0) {
      l1 -= 6; l0 -= 2;
      printf("o");
    } else {
      l1 -= 5; l0 -= 3;
      printf("g");
    }
  }

  return 0;
}