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
41
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n = *istream_iterator<int>(cin);
	string str = *istream_iterator<string>(cin);
	int counter = 0, len = n;
	for (auto& c : str)counter += c - 48;
	counter -= n * 3;
	if (counter < 0)
	{
		cout << "NIE\n";
		return 0;
	}
	string res = "";
	while (len && counter > 2)
	{
		counter -= 3;
		res.push_back(111);
		len--;
	}
	while (len && counter > 1)
	{
		counter -= 2;
		res.push_back(103);
		len--;
	}
	while (len && counter)
	{
		counter--;
		res.push_back(101);
		len--;
	}
	while (len)
	{
		res.push_back(97);
		len--;
	}
	if (res.length() != n)cout << "NIE\n"; else cout << res << '\n';
	return 0;
}