#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  string S;
  cin >> N >> S;
  vector<long long> ans(N, 0);
  long long cnt[26] = {0};
  for (long long i = 0; i < N; i++) {
    long long now = S[i] - 'a';
    long long tmp;
    long long ma = 0;
    for (long long j = 0; j < 26; j++) {
      if (now >= cnt[j]) {
        if (ma <= cnt[j]) {
          tmp = j;
          ma = cnt[j];
        }
      }
    }
    cnt[tmp] = now;
    ans[i] = tmp;
  }
  long long res = 0;
  for (long long i = 0; i < N; i++) {
    ans[i] = (26 - ans[i]);
    chmax(res, ans[i]);
  }
  cout << res << endl;
  for (long long i = 0; i < N; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
