#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  map<char, int> mp;
  map<int, int> finalans;
  map<int, int> tmpans;
  finalans[0] = 1;
  mp[s[0]]++;
  tmpans[1] = 1;
  for (int i = 1; i < n; i++) {
    int tmp = 0;
    for (char c = s[i] + 1; c <= 'z'; c++) {
      tmp = max(tmp, mp[c]);
    }
    finalans[i] = tmp + 1;
    tmpans[finalans[i]] = 1;
    mp[s[i]] = max(mp[s[i]], finalans[i]);
  }
  cout << tmpans.size() << '\n';
  for (int i = 0; i < n; i++) {
    cout << finalans[i] << " ";
  }
  return 0;
}
