#include <bits/stdc++.h>
using namespace std;
const int maxx = 600010;
int t, n, m;
int total = 0, sum = 0, cnt = 0;
int ans[maxx], bj[maxx];
char c[maxx];
int main() {
  scanf("%d", &n);
  scanf(" %s", c + 1);
  for (register int i = 1; i <= n; i++) {
    int maxn = 0;
    for (register int j = c[i] - 'a' + 1; j <= 25; j++) maxn = max(maxn, bj[j]);
    ans[i] = maxn + 1;
    bj[c[i] - 'a'] = max(bj[c[i] - 'a'], maxn + 1);
    total = max(maxn + 1, total);
  }
  printf("%d\n", total);
  for (register int i = 1; i <= n; i++) printf("%d ", ans[i]);
  return 0;
}
