#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, k = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return k ? x : -x;
}
int n, t, maxn, s[1000010], ans[1000010];
char ch;
int main() {
  n = read();
  for (int num = 0; num < n; num++) {
    cin >> ch;
    maxn = 0;
    for (int i = ch - 'a' + 1; i < 26; i++) maxn = max(maxn, s[i]);
    ans[num] = maxn + 1;
    s[ch - 'a'] = max(s[ch - 'a'], maxn + 1);
    t = max(t, maxn + 1);
  }
  printf("%d\n", t);
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
}
