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

int main() {
  vector<int> t;
  int n;
  int count0 = 0;
  int count1 = 0;
  string s;
  cin >> n >> s;
  for (auto x : s) {
    if (x == '0' && count0 < n) count0++;
    else if (x == '1' && count1 < 2 * n) count1++;
    else t.push_back(x - '0');
  }
  auto rng = std::default_random_engine {};
  

  int counter = 0;

  for (int i = 0; i < counter; i++) {

  }

  int count[2];
  count[0] = 0;
  count[1] = 0;
  for (auto x : t) {
    count[x]++;
  }
  int size = t.size();
  if (size % 5 != 0) {
    cout << "NIE";
    return 0;
  }
 
  char chars[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  size = size / 5;
  vector<char> ans;
  for (int i = 0; i < size; i++) {
    int c1 = count[1];
    int c0 = count[0];
    if (c1 == 0 || c0 == 0) {
      cout << "NIE";
      return 0;
    }
    if (c0 >= c1) {
      if (c0 - c1 == 0) {
        count[0] -= 2;
        count[1] -= 3;
        ans.push_back('g');
      }
      else if (c0 - c1 == 1 || c0 - c1 == 2) {
        count[0] -= 3;
        count[1] -= 2;
        ans.push_back('c');
      }
      else{
        count[0] -= 4;
        count[1] -= 1;
        ans.push_back('a');
      }
    }
    else {
      if (c1 - c0 == 1 || c1 - c0 == 2) {
        count[1] -= 3;
        count[0] -= 2;
        ans.push_back('g');
      }
      else {
        count[1] -= 4;
        count[0] -= 1;
        ans.push_back('o');
      }
    }
    
  }
  
  for (auto x : ans) cout << x;


}