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
#include <iostream>

using namespace std;

int n, ile, low, high;
char a;
int a3, c4, g5, o6;
int ile0;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin  >>    n;
    low  = 3 * n;
    high = 6 * n;
    for(int i = 0; i < 8*n; i++)
    {
        cin >> a;
        ile += (a == '1');
    }

    // cout << low << ' ' << high << ' ' << ile << endl;;

    if(ile < low or ile > high)
    {
        cout << "NIE";
        return 0;
    }
    int q = ile - low; //ile zostało wstępnie zakładając wszędzie a
    a3 = n;
    while(q >= 3)
    {
        o6++;
        a3--;
        q -= 3;
    }
    if(q == 2)
    {
        a3--;
        g5++;
        q -= 2;
    }
    if(q == 1)
    {
        a3--;
        c4++;
        q -= 1;
    }
    for(int i = 0; i < a3; i++)
        cout << 'a';
    for(int i = 0; i < c4; i++)
        cout << 'c';
    for(int i = 0; i < g5; i++)
        cout << 'g';
    for(int i = 0; i < o6; i++)
        cout << 'o';
    
    ile0 = 8*n - ile;
    
    ile0 -= a3*5;
    ile0 -= c4*4;
    ile0 -= g5*3;
    ile0 -= o6*2;
    if(ile0) cout << "AKLAFHHDAKHGLAD";


    
}