#include <bits/stdc++.h>
using namespace std;
char str[200005];
bool vis[26];
int val[26], col[200005];
int main() {
  int n;
  scanf("%d %s", &n, str);
  int mx = 0;
  for (int i = n - 1; i >= 0; i--) {
    vis[str[i] - 'a'] = 1;
    for (int j = 0; j < (str[i] - 'a'); j++)
      if (vis[j]) val[str[i] - 'a'] = max(val[str[i] - 'a'], val[j] + 1);
    col[i] = val[str[i] - 'a'];
    mx = max(mx, col[i]);
  }
  printf("%d\n", mx + 1);
  for (int i = 0; i < n; i++) printf("%d ", col[i] + 1);
  puts("");
  return 0;
}
