#include <bits/stdc++.h>
using namespace std;
char c[200001], nr[28];
int culori[200001];
int main() {
  int ulc = 1, i, j, n;
  bool ok = 0;
  char pen = 'a', max3 = 'a', ul = 'a';
  cin >> n;
  for (i = 1; i <= 27; i++) nr[i] = 'a';
  for (i = 1; i <= n; i++) cin >> c[i];
  for (i = 1; i <= n; i++) {
    ok = 1;
    for (j = 1; j <= ulc && ok; j++) {
      if (c[i] >= nr[j]) {
        ok = 0;
        nr[j] = c[i];
        culori[i] = j;
      } else {
        if (j == ulc) ulc++;
      }
    }
  }
  cout << ulc << '\n';
  for (i = 1; i <= n; i++) cout << culori[i] << " ";
  return 0;
}
