#include <bits/stdc++.h>
using namespace std;
char s[200009];
int num[30];
int res[200009];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j < 28; j++) {
      if (s[i] >= num[j]) {
        res[i] = j;
        num[j] = s[i];
        ans = max(ans, j);
        break;
      }
    }
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << res[i] << " ";
  cout << endl;
  return 0;
}
