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
#include <cstdio>
#include <map>
using namespace std;

const int maxN = 1e6 + 10;
int N;
char s[maxN];
int numof[16];

int main() {
    scanf("%d%s", &N, s);
    int sum = 0;
    for (int i = 0; i < 8 * N; ++i)
        sum += s[i] - '0';

    map<int, char> symbols;
    symbols[3] = 'p';
    symbols[4] = 'c';
    symbols[5] = 'g';
    symbols[6] = 'w';

    if (sum < 3 * N || sum > 6 * N) {
        puts("NIE");
        return 0;
    }

    sum -= 3 * N;
    numof[6] = sum / 3;
    numof[5] = sum % 3 == 2;
    numof[4] = sum % 3 == 1;
    numof[3] = N - (sum + 2) / 3;
    for (int i = 3; i <= 6; ++i) {
        while (numof[i]) {
            printf("%c", symbols[i]);
            numof[i]--;
        }
    }

    return 0;
}