#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, ans = 1, x;
  cin >> n;
  string s;
  long long int col[n];
  cin >> s;
  col[0] = 1;
  map<char, long long int> mp;
  mp[s[0]] = 1;
  for (long long int i = 1; i < s.size(); i++) {
    x = -1;
    for (char ch = s[i] + 1; ch <= 'z'; ch++) {
      x = max(x, mp[ch]);
    }
    if (x == -1) {
      x = 0;
    }
    col[i] = x + 1;
    mp[s[i]] = x + 1;
    ans = max(x + 1, ans);
  }
  cout << ans << "\n";
  for (long long int i = 0; i < n; i++) {
    cout << col[i] << " ";
  }
}
