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

using namespace std;

struct TestCase
{
  size_t letter_count;
  size_t ones;
  size_t zeros;
};

TestCase read_test_case();
void solve_test_case(const TestCase&);

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve_test_case(read_test_case());
}

TestCase read_test_case()
{
  TestCase tc;
  cin >> tc.letter_count;
  tc.ones = tc.zeros = 0;
  string data;
  cin >> data;
  for (auto c : data)
    if (c == '0')
      tc.zeros++;
    else
      tc.ones++;
  return tc;
}

void solve_test_case(const TestCase& tc)
{
  const size_t min_popcount = 3;
  const size_t max_popcount = 6;
  const map<size_t, char> popcount_to_letter = {
      {3, 'p'},
      {4, 'x'},
      {5, 'z'},
      {6, 'w'},
  };

  if (tc.ones < min_popcount * tc.letter_count ||
      tc.ones > max_popcount * tc.letter_count)
  {
    cout << "NIE\n";
    return;
  }

  size_t remaining = tc.ones - 3 * tc.letter_count;
  for (size_t i = 0; i < tc.letter_count; i++)
  {
    size_t add = min(remaining, static_cast<size_t>(3));
    cout << popcount_to_letter.at(3 + add);
    remaining -= add;
  }
  cout << "\n";
}