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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
std::vector<char> result;
int zero_counter = 0;
int one_counter = 0;
int difference;

bool counters_equal()
{
	while (zero_counter > 0)
	{
		result.push_back('c');
		zero_counter -= 4;
	}
	if (zero_counter == 0)
		return true;
	return false;
}

bool zero_is_bigger()
{
	while (one_counter > 0 && zero_counter > 0 && one_counter != zero_counter)
	{
		result.push_back('a');
		one_counter -= 3;
		zero_counter -= 5;
		difference -= 2;
	}
	if (one_counter == zero_counter)
		return counters_equal();
	return false;
}

bool one_is_bigger()
{
	while (one_counter > 0 && zero_counter > 0 && one_counter != zero_counter)
	{
		if (difference >= 4)
		{
			result.push_back('o');
			one_counter -= 6;
			zero_counter -= 2;
			difference -= 4;
		}
		else
		{
			result.push_back('n');
			one_counter -= 5;
			zero_counter -= 3;
			difference -= 2;
		}
	}
	if (one_counter == zero_counter)
		return counters_equal();
	return false;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 8 * n; i++)
	{
	read:
		char bit;
		scanf("%c", &bit);
		if (bit == '1')
			one_counter++;
		else if (bit == '0')
			zero_counter++;
		else
			goto read;
	}
	difference = std::abs(zero_counter - one_counter);
	bool result_exists = true;
	if (difference % 2 == 1)
		result_exists = false;
	else if (zero_counter > one_counter)
		result_exists = zero_is_bigger();
	else if (one_counter > zero_counter)
		result_exists = one_is_bigger();
	else
		result_exists = counters_equal();
	if (result_exists)
	{
		for (char letter : result)
		{
			printf("%c", letter);
		}
	}
	else
	{
		printf("NIE");
	}
	printf("\n");
}