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
#include <algorithm>
#include <cstdio>

using namespace std;

const char* letters = "...algorytm";

bool solve(int n, char* a) {
  int ones = 0;
  for(int i=0;i<8*n;i++) {
    if(a[i]=='1') {
      ones++;
    }
  }
  int d = ones / n;
  int r = ones % n;

  if((r == 0) && (d >= 3) && (d <= 6)) {
    fill(a, a+n, letters[d]);
    a[n] = '\0';
    return true;
  }

  if((d >= 3) && (d <= 5)) {
    fill(a, a+r, letters[d+1]);
    fill(a+r, a+n, letters[d]);
    a[n] = '\0';
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
  int n;
  char a[808080];
  scanf("%d", &n);
  scanf("%s", a);

  bool possible = solve(n, a);

  if(possible) {
    printf("%s\n", a);
  } else {
    printf("NIE\n");
  }
  return 0;
}