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

using ll = long long;
unordered_map<int, char> a{};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    a[3] = 'a';
    a[4] = 'e';
    a[5] = 'g';
    a[6] = 'o';

    int n{};
    cin >> n;
    string s{};
    cin >> s;
    int sum{};
    for (int i = 0; i < 8*n; i++) sum += s[i]-'0';
    vector<int> v(n, 3);
    int sum2 = 3*n;
    int i{};
    while (sum2 < sum and i < n) {
        if (sum2-3+6 <= sum) {
            v[i] = 6;
            sum2 += 3;
        } else if (sum2-3+5 <= sum) {
            v[i] = 5;
            sum2 += 2;
        } else {
            v[i] = 4;
            sum2++;
        }
        i++;
    }
    if (sum2 != sum) {
        cout << "NIE\n";
        return 0;
    }
    for (auto el : v) cout << a[el];
    cout << "\n";
    return 0;
}