#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p, i, col = 1;
  char c;
  scanf("%d", &n);
  char s[200005];
  int ans[200005];
  vector<int> v[200001];
  int ind[200000] = {};
  memset(ind, -1, sizeof(ind));
  scanf("%c", &c);
  for (i = 0; i < n; i++) {
    scanf("%c", &c);
    p = 0;
    while (1) {
      if (ind[p] == -1) {
        ind[p]++;
        v[p].push_back((int)c);
        ans[i] = p + 1;
        break;
      }
      if (v[p][ind[p]] <= (int)c) {
        ind[p]++;
        v[p].push_back((int)c);
        ans[i] = p + 1;
        break;
      } else {
        p++;
      }
    }
  }
  for (i = 0; i < n; i++) {
    if (col < ans[i]) col = ans[i];
  }
  printf("%d\n", col);
  for (i = 0; i < n; i++) {
    printf("%d ", ans[i]);
  }
}
