#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, ans = 1, col[maxn], book[27];
char S[maxn];
int se[26][27];
int main() {
  scanf("%d", &n);
  scanf("%s", S + 1);
  se[S[1] - 'a'][1] = 1;
  col[1] = 1;
  for (int i = 2; i <= n; i++) {
    int v = S[i] - 'a';
    for (int j = 1; j <= 26; j++) book[j] = 0;
    for (int j = v + 1; j < 26; j++)
      for (int k = 1; k <= 26; k++)
        if (se[j][k]) book[k] = 1;
    for (int j = 1; j <= 26; j++)
      if (book[j] == 0) {
        col[i] = j;
        break;
      }
    se[v][col[i]] = 1;
    ans = max(ans, col[i]);
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d", col[i]);
    if (i == n)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
