#include <bits/stdc++.h>
char x[200005];
int dp[200005], maxdp[26];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", x + 1);
  for (int i = 1; i <= n; i++) {
    x[i] = x[i] - 'a';
    dp[i] = 1;
  }
  maxdp[x[1]] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = x[i] + 1; j < 26; j++) {
      dp[i] = dp[i] < maxdp[j] + 1 ? maxdp[j] + 1 : dp[i];
    }
    if (dp[i] > maxdp[x[i]]) maxdp[x[i]] = dp[i];
  }
  int ans = -1;
  for (int i = 1; i <= n; i++) {
    if (dp[i] > ans) ans = dp[i];
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) printf("%d ", dp[i]);
  return 0;
}
