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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int number_of_ones(int x)
{
    int counter = 0;
    while(x)
    {
        if (x & 1) {
            counter++;
        }
        x /= 2;
    }
    return counter;
}
int main()
{
    ios_base::sync_with_stdio(false);
    int n, ones = 0;
    string s;
    cin >> n >> s;

    // vector<pair<char, int>> letters;
    // vector<int> letter_counter('z'-'a' + 1, 0);
    
    // for (int i='a'; i <= 'z'; i++)
    // {
    //     int counter = number_of_ones(i);
    //     letter_counter[i - 'a'] = counter;

    //     if (find_if(letters.begin(), letters.end(), [counter](auto x){return x.second == counter;}) == letters.end())
    //     {
    //         letters.push_back({i, counter});
    //     }
    // }
    ones = accumulate(s.begin(), s.end(), 0, [](int acc, char c){return acc + (c == '1' ? 1 : 0);});

    // for (auto [c, counter] : letters) 
    // {
    //     cout << c << " " << counter << "\n";
    // }

    if (ones < 3*n || ones > 6*n) 
    {
        cout << "NIE";
        return 0;
    }

    int six = ones / 3 - n, other = ones % 3;
    int three = n - six;
    for (int i=0; i < six; i++)
    {
        cout << 'o'; //6 ones
    }
    if (other == 1) 
    {
        cout << 'c'; // 4 ones
        three--;
    }
    else if (other == 2) {
        cout << 'g';//5 ones
        three--;
    }

    for (int i=0; i < three; i++)
    {
        cout << 'a'; //3 ones
    }


    // vector<char> backpack(ones+1, 0);
    // backpack[0] = 1;

    // for(int i=1; i <= ones; i++)
    // {
    //     for (auto [c, count] : letters)
    //     {
    //         if (i - count >= 0 && backpack[i-count])
    //         {
    //             backpack[i] = c;
    //         }
    //     }
    // }

    // if (!backpack[ones] || ones == 0) {
    //     cout << "NIE";
    //     return 0;
    // }

    // while(ones != 0) {
    //     cout << backpack[ones];
    //     ones -= letter_counter[backpack[ones] - 'a'];
    // }
}