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

using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);

    ll n;
    cin >> n;

    char c;
    ll one = 0, zero = 0;
    for (int i = 0; i < 8*n; ++i) {
        cin >> c;
        if (c == '1') one++;
        else zero++;
    }

    for (int i = 0; i < n; ++i) {
        zero--;
        one -= 2;
    }


    // a = 1 // c = 2 // g = 3 // o = 4

    if (one > 4 * n || one < n) {
        cout << "NIE";
        return 0;
    }

    for (int i = 0; i < n; ++i) {
        ll id = one / n;
        if (i < one % n) id += (one % n > 0);

        switch (id) {
            case 1: cout << 'a'; break;
            case 2: cout << 'c'; break;
            case 3: cout << 'g'; break;
            case 4: cout << 'o'; break;
        }
    }
}