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
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main() {
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string word;
    cin >> word;
    int ones = 0;
    for(auto& c: word) {
        if(c == '1') {
            ++ones;
        }
    }
    // cout << "ones=" << ones << endl;
    if(ones < 3 * n || ones > 6 * n) {
        cout << "NIE" << endl;
        return 0;
    }
    ones -= 3*n;
    vector<char> letters;
    for(int i = 0; i < n; ++i) {
        int extra = min(ones, 3);
        ones -= extra;
        // cout << "extra, ones=" << extra << " " << ones << endl;

        char chr;
        switch(extra) {
            case 0:
                chr = 'a';
                break;
            case 1:
                chr = 'c';
                break;
            case 2:
                chr = 'g';
                break;
            case 3:
                chr = 'o';
                break;
        }
        letters.push_back(chr);
    }
    string res(letters.begin(), letters.end());
    cout << res << endl;
}