#include <bits/stdc++.h>
using namespace std;
inline int R() {
  char c;
  int sign = 1, res = 0;
  while ((c = getchar()) > '9' || c < '0')
    if (c == '-') sign = -1;
  res += c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  return res * sign;
}
const int Maxn = 2e5 + 5;
int n, a[Maxn], ans[Maxn];
int s[30];
int main() {
  n = R();
  char c;
  for (int i = 1; i <= n; i++) {
    while ((c = getchar()) > 'z' || c < 'a')
      ;
    a[i] = c - 'a' + 1;
  }
  int M = 1, now;
  for (int i = 1; i <= n; i++) {
    now = 1;
    for (int j = a[i] + 1; j <= 26; j++)
      if (s[j]) now = max(now, s[j] + 1);
    ans[i] = now;
    M = max(now, M);
    s[a[i]] = now;
  }
  printf("%d\n", M);
  for (int i = 1; i <= n; i++) printf("%d ", ans[i]);
}
