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
// Krzysztof Baranski (2021.12.03)
#include <cstdio>
#include <string>

using namespace std;

int main() {
    register int n;
    register int x=0, y=0;

    scanf("%d\n", &n);
    register int b = n<<3;
    while(b--) getchar()=='0' ? ++x : ++y;

    // printf("(%d, %d)\n", x, y);

    if((x-y) % 2 != 0) {
        printf("NIE\n");
        return 0;
    }

    string message;

    while(n--) {
        if(x == y) {
            x -= 4;
            y -= 4;
            message.push_back('q');
            // printf("q -> (%d, %d)\n", x, y);
        } else if(y >= x+4) {
            x -= 2;
            y -= 6;
            message.push_back('o');
            // printf("o -> (%d, %d)\n", x, y);
        } else if(y > x) {
            x -= 3;
            y -= 5;
            message.push_back('n');
            // printf("n -> (%d, %d)\n", x, y);
        } else {
            x -= 5;
            y -= 3;
            message.push_back('p');
            // printf("p -> (%d, %d)\n", x, y);
        }
    }

    if(x == 0 && y == 0) {
        printf("%s\n", message.c_str());
    } else {
        printf("NIE\n");
    }

    return 0;
}