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

#define ll long long
int quantity;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  cin >> quantity;
  string message;
  cin >> message;
  int counter = 0;

  for (auto const &c : message) {
    counter += (c == '1');
  }

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

  int a = quantity;
  int c = 0;
  int g = 0;
  int o = 0;
  int diff = counter - 3 * quantity;

  o += diff / 3;
  diff -= o * 3;
  a -= o;
  while (o--) {
    cout << "o";
  }

  g += diff / 2;
  diff -= g * 2;
  a -= g;
  while (g--) {
    cout << "g";
  }

  c += diff;
  a -= c;
  while (c--) {
    cout << "c";
  }

  while (a--) {
    cout << "a";
  }
}