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
#include <cstdio>
#define BITS 1000000

char s[BITS];

const char chars[5] = "acgw";

int main() {

    int n, ones = 0, zeros = 0;
    scanf("%d", &n);
    scanf("%s", s);
    for(int i = 0; i < 8 * n; i++) {
        if (s[i] == '0') zeros++;
        else ones++;
    }

    //printf("%d %d\n", zeros, ones);

    zeros -= 2 * n;
    ones -= 3 * n;

    if (zeros < 0 || ones < 0) {
        printf("NIE\n");
        return 0;
    }

    for (int i = 0; i < n; i++) {
        for (int k = 3; k >= 0; k--) {
            if (ones >= k) {
                printf("%c", chars[k]);
                ones -= k;
                zeros -= (3 - k);
                break;
            }

        }
    }

    printf("\n");
}