#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ios_base& scientific(ios_base & str);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans[n];
  char t, ps;
  int f = 0;
  t = ps = 'a';
  int ts = 2;
  int maxx = 0;
  char pt = 'z';
  char tss[10000];
  for (int i = 0; i < 10000; i++) {
    tss[i] = 'a';
  }
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 10000; j++) {
      if (s[i] >= tss[j]) {
        ans[i] = j;
        tss[j] = s[i];
        if (maxx < j) {
          maxx = j;
        }
        break;
      }
    }
  }
  cout << maxx << endl;
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
