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
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
//#include <x86intrin.h>

using std::size_t;

int n;         // number of bytes
std::string s; // list of bits;

int main() {
  std::ios::sync_with_stdio(false);

  std::cin >> n;

  std::cin >> s;

  n = int(s.size() / 8);

  auto n0 = std::count(s.begin(), s.end(), '0');
  auto n1 = std::count(s.begin(), s.end(), '1');

  auto y0 = n0;
  auto y1 = (-n0 - n1) / 8;
  decltype(y1) y2, y3;

  auto A = n0 - (n0 + n1) / 8;
  auto B = -((n0 + n1) / 8 + n0);
  auto C = (n0 + n1) / 8;

  if (!(2 * B <= -3 * A)) {
    std::cout << "NIE\n";
    return 0;
  }

  if (!(B <= -3 * C)) {
    std::cout << "NIE\n";
    return 0;
  }

  if (-2 * C <= -A) {
    y3 = -C;
    y2 = -C;
  } else if (-C <= -2 * A - B) {
    y3 = C - A;
    y2 = -C;
  } else {
    y3 = A + B;
    y2 = -2 * A - B;
  }

  auto x0 = -y0 - y1 - y2 - y3;
  auto x1 = y0 - y1 + y2 + 2 * y3;
  auto x2 = y2 - y3;
  auto x3 = y1 - y2;

/*std::cout << y0 << " " << y1 << " " << y2 << " " << y3 << "\n";
  std::cout << x0 << " " << x1 << " " << x2 << " " << x3 << "\n";
  std::cout << "\n";
  std::cout << "y2 <= -y3 - " << A << "\n";
  std::cout << "y2 >= -2*y3 + " << B << "\n";
  std::cout << "y2 >= y3\n";
  std::cout << "y2 <= " << -C << "\n";

  auto sum = 0;
  sum += x0 * _popcnt32('o') + x1 * _popcnt32('g') + x2 * _popcnt32('c') +  x3 * _popcnt32('a');
  //std::cout << "Sum = " << sum << std::endl;
  //std::cout << "n0 = " << n0 << std::endl;
  //std::cout << "n1 = " << n1 << std::endl;
  if (n0 == 8*n - sum && n1 == sum)
    std::cout << "Correct!\n";
  else
    std::cout << "Fail!\n";*/

  std::cout << std::string(size_t(x0), 'o');
  std::cout << std::string(size_t(x1), 'g');
  std::cout << std::string(size_t(x2), 'c');
  std::cout << std::string(size_t(x3), 'a');
  std::cout << '\n';
}