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
#include <bits/stdc++.h>

using namespace std;

int dp[100001];


int main() {
    int n; char c;
    scanf("%d",&n);
    //printf("%d\n",n);
    int ones=0;
    c=getchar();
    for(int j=0; j < 8*n; ++j) {
            c=getchar();
      //      printf("%c",c);
            if(c=='1') ones++;
    }
    //printf("\n");
    //printf("ones: %d\n", ones);
    int threes=ones / 3;
    //printf("threes: %d\n", threes);

    int remainder= ones % 3;
    //printf("rem: %d\n", remainder);


    if(threes < n) { printf("NIE\n"); return 0; }
    int sixes = threes - n;
    //printf("sixes: %d\n", sixes);

    if(threes % 2 == 1) {
        // mozna zlaczyc wszystko poza ostatnia
        if(2*sixes > threes -1) {
            printf("NIE\n");
            return 0;
        }
    }
    else {
        if(remainder ==  0) {
            if( 2*sixes > threes) {
               printf("NIE\n");
               return 0;
            }
        }
        else {
            if( 2*sixes > threes -2) {
                printf("NIE\n");
                return 0;

            }

        }
    }

    for(int i=0; i<sixes; ++i) printf("w");
    for(int i=sixes+1; i<=n-1; ++i) printf("a");
    if(sixes < n) {
       if(remainder==0) { printf("a\n"); return 0; }
       if(remainder==1) { printf("c\n"); return 0; }
       printf("g\n"); return 0;
    }
    printf("\n");
    return 0;
}