1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
using namespace std;
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  string s, res = "";
  cin >> n >> s;
  int ones = 0, k = 6;
  for(auto i : s) if (i == '1') ones++;
  char t[7] = {'.', '.', '.', 'a', 'c', 'g', 'o'};
  if (ones < n * 3 || n * 6 < ones){
    cout << "NIE\n";
    return 0;
  }
  for(int i = 0;i < n;i++){
    while (k > 3 && (ones - k) < 3 * (n - i - 1)) k--;
    res += t[k];
    ones -= k;
  }
  cout << res << '\n';
}