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
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <bits/stdc++.h>

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	int n;

	std::cin >> n;

	long long i0 = 0;
	long long i1 = 0;
	long long limit = 8*n;

	for(int i=0; i<limit; i++)
	{
		char c;
		std::cin >> c;
		if(c=='0') i0++;
		else if(c=='1') i1++;
	}

	std::vector<int> vz = {5,4,3,2};

	//std::cout << "0: " << i0 << " 1: " << i1 << "\n";

	std::map<int, int> mz;

	while(i1 > 0 && i0 > 0)
	{
		//std::cout << "loop/ 0: " << i0 << " 1: " << i1 << "\n";
		bool op=false;
		if(i0 > i1)
		{
			for(auto it=vz.begin(); it!=vz.end(); it++)
			{
				if(i0-*it >= 0 && i1-(8-*it) >=0)
				{
					mz[*it]++;
					i0-=*it;
					i1-=(8-*it);
					op = true;
				}
				if(op) break;
			}
		}
		else if(i1 > i0)
		{
			for(auto it=vz.rbegin(); it!=vz.rend(); it++)
			{
				if(i0-*it >= 0 && i1-(8-*it) >=0)
				{
					mz[*it]++;
					i0-=*it;
					i1-=(8-*it);
					op = true;
				}
				if(op) break;
			}
		}
		else if(i1==i0)// 1==0
		{
			mz[4]++;
			i0-=4;
			i1-=4;
			op = true;
		}
		
		if(not op)
		{
			break;
		}
	}

	if(mz.empty())
	{
		std::cout << "NIE\n";
		return 0;
	}

	while(i0 != 0 || i1 != 0)
	{
		bool op = false;
		if(i0 > i1) // add zero to set
		{
			auto it=mz.begin();
			if(it->first != 5)
			{
				int key = it->first;
				mz[key]--;
				mz[key+1]++;
				op = true;
			}
		}
		if(not op) break;
	}

	if(i1 != 0 || i0 != 0)
	{
		std::cout << "NIE\n";
		return 0;
	}
/*
	for(auto it=mz.begin(); it!=mz.end(); it++)
	{
		std::cout << "[" << it->first << " : " << it->second << "] ";
	}
	std::cout << "\n";
	std::cout << "0: " << i0 << " 1: " << i1 << "\n";
*/
	unsigned char lut[10];
	lut[5] = 'a';
	lut[4] = 'c';
	lut[3] = 'y';
	lut[2] = 'o';
	for(auto it=mz.begin(); it!=mz.end(); it++)
	{
		for(int i=0;i<it->second;i++)
		{
			std::cout << lut[it->first];
		}
	}
	std::cout << "\n";
	return 0;
}