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 main(){
	long long n, setBits = 0;
	char numToChar[4] = {'a', 'c', 'm', 'w'};
	cin >> n;
	for(int i = 0; i < 8 * n; i++){
		char temp;
		cin >> temp;
		setBits += (((int)temp) - 48);
	}
	if(setBits < 3 * n || setBits > 6 * n){
		cout << "NIE\n";
		return 0;
	}
 	setBits -= (n * 3);
 	long long arr[n] = {0};
 	long long idx = 0;
 	for(int i = 0; i < setBits; i++){
 		if(arr[idx] == 3){
 			idx++;
 		}
 		arr[idx]++;
 	}
 	for(int i = 0; i < n; i++){
 		cout << numToChar[arr[i]];
 	}
 	cout << endl;
}