#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 10;
int N;
char s[MAX];
int c[100], ans[MAX];
void upd(int p, int k) {
  for (; p; p -= p & -p) c[p] = max(c[p], k);
}
int query(int p) {
  int res = 0;
  for (; p <= 26; p += p & -p) res = max(res, c[p]);
  return res;
}
int main() {
  scanf("%d%s", &N, s + 1);
  int mx = 0;
  for (int i = 1; i <= N; i++) {
    int q = query(s[i] - 'a' + 2) + 1;
    mx = max(mx, q);
    ans[i] = q;
    upd(s[i] - 'a' + 1, q);
  }
  printf("%d\n", mx);
  for (int i = 1; i <= N; i++) printf("%d%s", ans[i], i == N ? "\n" : " ");
  return 0;
}
