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
#include <stdio.h>

size_t N;
char *buff;
int *cmps; // components
// char *output;
int main(void) {
	size_t ones=0;
	scanf("%lu", &N);
	buff = new char[8*N+1];
	scanf("%s", buff);
	for (size_t i=0; i<8*N; ++i)
		if (buff[i]=='1')
			++ones;

	// printf("%s\n", buff);
	// printf("ones: %lu\n", ones);

	bool possible=true;
	size_t c_end=0;
	cmps = new int[N];

	size_t c_low;
	size_t c_high;
	size_t x, y;
	size_t n = N;
	if (ones % 6 == 1) {
		if (ones < 7) { possible=false; goto finish; }
		cmps[c_end++] = 3;
		cmps[c_end++] = 4;
		ones -= 7;
		n -= 2;
	} else if (ones % 6 == 2) {
		if (ones < 8) { possible=false; goto finish; }
		cmps[c_end++] = 3;
		cmps[c_end++] = 5;
		ones -= 8;
		n -= 2;
	} else if (ones % 6 == 3) {
		cmps[c_end++] = 3;
		ones -= 3;
		n -= 1;
	} else if (ones % 6 == 4) {
		cmps[c_end++] = 4;
		ones -= 4;
		n -= 1;
	} else if (ones % 6 == 5) {
		cmps[c_end++] = 5;
		ones -= 5;
		n -= 1;
	}

	c_low  = ones / 6;
	c_high = ones / 3;
	if (n > c_high || n < c_low) { possible=false; goto finish; }

	// x = ones/3 - ones;
	// y = ones/3 - 2*x;
	x = c_low;
	y = 0;
	while (x + y != n && x != 0) {
		--x;
		y += 2;
	}

	for (size_t i=0; i<x; ++i) {
		cmps[c_end++] = 6;
		// printf("6 ");
	}
	for (size_t i=0; i<y; ++i) {
		cmps[c_end++] = 3;
		// printf("3 ");
	}
	// for (size_t i=0; i<c_end; ++i) {
	// 	printf("%i ", cmps[i]);
	// }
	// printf("\n");

	for (size_t i=0; i<c_end; ++i) {
		switch (cmps[i]) {
			// case '1':
			// 	break;
			// case '2':
			// 	break;
			case 3:
				printf("a");
				break;
			case 4:
				printf("c");
				break;
			case 5:
				printf("g");
				break;
			case 6:
				printf("w");
				break;
			default:
				break;
		}
	}
	printf("\n");

finish:
	if (!possible) {
		printf("NIE\n");
	}
	return 0;
}