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

int main() 
{
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int C[2] = {0, 0};
	for (char &c : s) {
		C[c-'0']++;
	}
	vector <string> Bits(n);
	for (int i = 0; i < n; i++) {
		Bits[i] = "01101";
		C[0] -= 2;
		C[1] -= 3;
	}
	if (C[0] < 0 || C[1] < 0) {
		cout << "NIE" <<endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			int b = (C[0] > 0) ? 0 : 1;
			C[b]--;
			Bits[i].push_back('0' + b);
		}
	}
	
	string ans;
	for (int i = 0; i < n; i++) {
		int c = strtol(Bits[i].c_str(), NULL, 2);
		ans.push_back(c);
	}
	cout << ans <<endl;
	return 0;
}