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
#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main()
{
    int n;
    string b;

    cin >> n >> b;

    int active = 0;
    for (int i = 0; i < b.length(); ++i)
    {
        if (b[i] == '1')
        {
            ++active;
        }
    }

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

    int add3 = 0;
    int add4 = 0;
    int add5 = 0;
    int add6 = 0;

    if (active % 3 == 1)
    {
        add4 += 1;
        active -= 4;
    }
    else if (active % 3 == 2)
    {
        add4 += 1;
        active -= 5;
    }

    add3 = active / 3;

    while (add3 + add4 + add5 + add6 > n)
    {
        if (add3 >= 2)
        {
            add3 -= 2;
            ++add6;
        }
        else {
            break;
        }
    }

    if (add3 + add4 + add5 + add6 == n)
    {
        while (add3--)
        {
            cout << "a";
        }
        while (add4--)
        {
            cout << "c";
        }
        while (add5--)
        {
            cout << "g";
        }
        while (add6--)
        {
            cout << "o";
        }
    }
    else
    {
        cout << "NIE";
    }



    //3a, 4c, 5g ,6o
}