#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ch[26] = {0};
  memset(ch, 0, sizeof(ch));
  long long re[n];
  long long ma = 0;
  for (long long i = 0; i < n; i++) {
    map<long long, long long> mp;
    long long c = 1;
    for (long long j = s[i] - 'a' + 1; j < 26; j++) {
      if (ch[j] != 0) {
        if (mp[ch[j]] == 0) {
          c++;
          mp[ch[j]] = 1;
        }
      }
    }
    ma = max(ma, c);
    re[i] = c;
    ch[s[i] - 'a'] = c;
  }
  cout << ma << endl;
  for (long long i = 0; i < n; i++) cout << re[i] << " ";
  return 0;
}
