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
// C2 - Zaklocenia
#include <iostream>
using namespace std;

char getCharRepresentative(int size) {
	switch(size) {
		case 3:
			return('a');
		case 4:
			return('c');
		case 5:
			return('g');
		case 6:
			return('o');
		default:
			return('?');
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	int n, sum, shorterSize, longerSize, shorterCount, longerCount;
	char b;
	
	cin >> n;
	
	sum = 0;
	for (int i = 0; i < 8 * n; ++i) {
		cin >> b;
		sum += b - '0';
	}
	if 	(sum < 3 * n || sum > 6 * n) {
		cout << "NIE";
	} else {
		shorterSize = sum / n;
		longerSize = shorterSize + 1;
		longerCount = sum - shorterSize * n;
		shorterCount = n - longerCount;
		
		for (int i = 0; i < shorterCount; ++i) {
			cout << getCharRepresentative(shorterSize);
		}
		for (int i = 0; i < longerCount; ++i) {
			cout << getCharRepresentative(longerSize);
		}
	}
	
	return 0;
}