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

#define MAX_N	100010

int N;
char S[8 * MAX_N];
int c1, ca, co;

int main() {
	scanf("%d", &N);
	scanf("%s", S);

	for (int i = 0; i < 8 * N; ++i) {
		if (S[i] == '1') {
			c1++;
		}
	}

	if (c1 < 3 * N || c1 > 6 * N) {
		printf("NIE\n");
		return 0;
	}

	co = (c1 - 3 * N) / 3;
	ca = (c1 - 6 * co) / 3 - 1;
	c1 = c1 - 6 * co - 3 * ca;

	for (int i = 0; i < ca; ++i) {
		S[i] = 'a';
	}
	switch (c1) {
		case 3:
			S[ca] = 'a';
			break;
		case 4:
			S[ca] = 'c';
			break;
		case 5:
			S[ca] = 'g';
			break;
	}
	for (int i = 0; i < co; ++i) {
		S[ca + 1 + i] = 'o';
	}
	S[ca + 1 + co] = 0;

	printf("%s\n", S);
	return 0;
}