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

int main() {
	int n;
	cin >> n;
	int ones = 0;
	for (int i=8*n; i>0; i--) {
		char c;
		cin >> c;
		if (!cin.good()) return 1;
		if (c != '0' && c != '1') return 2;
		ones += c == '1';
	}
	int a = ones / n;
	int b = ones % n;
	if (a < 3 || (ones + n - 1) / n > 6) {
		cout << "NIE\n";
		return 0;
	}
	int k = a < 6 ? (b+5-a)/(6-a) : 0;
	if (k > n) return 3;
	for (int i=n-k; i>0; i--) {
		cout << "acgo"[a-3];
		ones -= a;
	}
	for (int i=k; i>0; i--) {
		int x = min(ones,6);
		cout << "acgo"[x-3];
		ones -= x;
	}
	cout << "\n";
	return 0;
}