#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int now[30];
char s[maxn];
int num[maxn];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 30; j++) {
      if (s[i] >= now[j]) {
        num[i] = j;
        now[j] = s[i];
        ans = max(ans, j);
        break;
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    printf("%d ", num[i]);
  }
  printf("\n");
}
