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

const int max_size = 5 * 100 * 1000 + 20;

int n;
std::string slowo;
int s;

int x, y, z, t;
char answer[max_size];
int itr;

int main(){
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(0);
        std::cout.tie(0);

        std::cin >> n;
        std::cin >> slowo;

        s = 0;
        for(int i = 0; i < 8*n; i++){
                if(slowo[i] == '1')
                        s++;
        }

        x = 4*n - s;
        y = s - 3*n;
        z = 0;
        t = 0;

        if(x < 0){
                t = (-1 * x) / 2;
                if(x + 2*t < 0) z = 1;

                x += z + 2*t;
                y -= 2*z + 3*t;
        }

        if(y < 0)
                std::cout << "NIE\n";
        else {
                itr = 0;

                //std::cout << x << " " << y << " " << z << " " << t << "\n";

                for(int i = 0; i < x; i++, itr++)
                        answer[itr] = 'a';
                for(int i = 0; i < y; i++, itr++)
                        answer[itr] = 'c';
                for(int i = 0; i < z; i++, itr++)
                        answer[itr] = 'g';
                for(int i = 0; i < t; i++, itr++)
                        answer[itr] = 'o';

                answer[itr] = 0;

                std::cout << answer << "\n";
        }
        return 0;
}