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


using namespace std;


string xd(int n, int j, int z, int pos){
	if (!n || pos == (int('z')+1)){
		if (!j && !z && !n) return "";
		else return "$$";
	}
	int kod = int(pos);
	int ile = __builtin_popcount(kod);
	if (j >= ile && z >= 8 - ile ){
		if (xd(n-1, j - ile, z - 8 + ile, pos)[0] != '$') return char(pos) + xd(n-1, j - ile, z - 8 + ile, pos);
	}
	return xd(n, j, z, pos+1);
}

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int z = 0, j = 0;
	for (int i = 0; i < 8*n; i++){
		if (s[i] == '0') z++;
		else j++;
	}
	string ans = xd(n, j, z, int('a'));
	if (ans[0] == '$') cout << "NIE" << endl;
	else cout << ans;
	return 0;
}