#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int clr[n];
  memset(clr, -1, sizeof(clr));
  vector<char> v;
  v.push_back(s[0]);
  clr[0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < v.size(); ++j) {
      if (v[j] <= s[i]) {
        clr[i] = j;
        v[j] = s[i];
        break;
      }
    }
    if (clr[i] == -1) {
      clr[i] = v.size();
      v.push_back(s[i]);
    }
  }
  cout << v.size() << "\n";
  for (int i = 0; i < n; ++i) cout << clr[i] + 1 << " ";
  return 0;
}
