#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n, 0);
  for (int i = (0); i < (n); i++) {
    a[i] = s[i] - 'a' + 1;
  }
  vector<int> ans(n, 0);
  deque<long long> d;
  for (int i = (0); i < (n); i++) {
    int p = upper_bound(d.begin(), d.end(), a[i]) - d.begin();
    if (p == 0) {
      d.push_front(a[i]);
    } else {
      d[p - 1] = a[i];
    }
    if (p == 0) p++;
    ans[i] = d.size() - p + 1;
  }
  cout << d.size() << endl;
  for (int i = (0); i < (n); i++) {
    if (i == 0)
      cout << ans[i];
    else
      cout << " " << ans[i];
  }
  cout << endl;
  return 0;
}
