#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
char s[maxn];
int n, mx = 0, ans[maxn], Max[maxn];
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; ++i) {
    int cnt = 0;
    for (int j = s[i] + 1; j <= 'z'; j++) cnt = max(cnt, Max[j]);
    cnt++;
    Max[s[i]] = cnt;
    ans[i] = cnt;
    mx = max(mx, cnt);
  }
  printf("%d\n", mx);
  for (int i = 0; i < n; ++i) printf("%d ", ans[i]);
  return 0;
}
