#include <bits/stdc++.h>
using namespace std;
int ans[200005];
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  };
  int n;
  cin >> n;
  string second;
  cin >> second;
  char ara[30];
  for (int i = 0; i < 26; i++) ara[i] = 'z' + 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (second[i] <= ara[j]) {
        ara[j] = second[i];
        ans[i] = j + 1;
        break;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt = max(ans[i], cnt);
  cout << cnt << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << ' ';
}
