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
#include <iostream>

constexpr int MAX_N = 500000;
constexpr int MIN_BITS_IN_CHAR = 3;
constexpr int MAX_BITS_IN_CHAR = 6;

char outputs[MAX_BITS_IN_CHAR + 1] = {
    0,
    0,
    0,
    'a',
    'c',
    'g',
    'o'
};


unsigned int countSetBits(char n)
{
    unsigned int count = 0;
    while (n) {
        count += n & 1;
        n >>= 1;
    }
    return count;
}

inline bool isSequencePossible(const int& numberOfOnes, const int& n) {
    return numberOfOnes >= MIN_BITS_IN_CHAR * n && numberOfOnes <= MAX_BITS_IN_CHAR * n;
}

inline int findNumberOfOnes(const int& n) {
    int numberOfBits = n * 8;
    int numberOfOnes = 0;
    while (true) {
        char c = getchar();
        if (c == '1') {
            numberOfOnes++;
            break;
        }
        if (c == '0')
            break;
    }
    for (int i = 0; i < numberOfBits - 1; i++) {
        char c = getchar();
        if (c == '1')
            numberOfOnes++;
    }
    return numberOfOnes;
}

inline int getLowerChar(const int& numberOfOnes, const int& n) {

    for (int i = MIN_BITS_IN_CHAR; i <= MAX_BITS_IN_CHAR; i++) {
        if (n * i > numberOfOnes)
            return i - 1;
    }
    return MAX_BITS_IN_CHAR;
}

void solve() {
	int n;
	std::cin >> n;
    int numberOfOnes = findNumberOfOnes(n);

    if (!isSequencePossible(numberOfOnes, n)) {
        std::cout << "NIE";
        return;
    }
    int lowerChar = getLowerChar(numberOfOnes, n);
    int higherCharsNumber = numberOfOnes - lowerChar * n;
    int lowerCharsNumber = n - higherCharsNumber;

    for(int i = 0; i < lowerCharsNumber; i++)
        putchar(outputs[lowerChar]);
    for (int i = 0; i < higherCharsNumber; i++)
        putchar(outputs[lowerChar + 1]);
}


int main() {
	solve();
	return 0;
}