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
#include <bits/stdc++.h>
using namespace std;

int n, ones, idx;
string s;
char letter[7];

int main() {
	cin >> n >> s;
	for (int i=0; i<8*n; i++) {
		ones += s[i] - '0';
	}
	if (ones < n * 3 || ones > n * 6) {
		cout << "NIE" << endl;
		return 0;
	}
	letter[3] = 'a';
	letter[4] = 'c';
	letter[5] = 'g';
	letter[6] = 'w';

	for (int i=0; i<n; i++) {
		idx = min(6, ones - (n - i - 1) * 3);
		cout << letter[idx];
		ones -= idx;
	}
	cout << endl;

	return 0;
}