#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int NINF = -INF - 1;
const int N = 2e5 + 5;
using namespace std;
char a[N];
int c[N];
int b[26];
int main() {
  int n, ans = 0, maxn = -1000000;
  scanf("%d", &n);
  scanf("%s", a);
  for (int i = 0; i < n; i++) {
    ans = 1;
    for (int j = a[i] - 'a' + 1; j < 26; j++) {
      ans = max(ans, b[j] + 1);
    }
    b[a[i] - 'a'] = ans;
    c[i] = ans;
    maxn = max(maxn, c[i]);
  }
  cout << maxn << endl;
  for (int i = 0; i < n; i++) printf("%d ", c[i]);
  printf("\n");
  return 0;
}
