#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    vector<long long> d(n, 0), fre(26, 0);
    fre[s[0] - 'a'] = 1;
    d[0] = 1;
    long long ans = 1;
    for (long long i = 1; i < n; i++) {
      long long cnt = 0, ind = s[i] - 'a';
      for (long long j = ind + 1; j < 26; j++) {
        cnt = max(cnt, fre[j]);
      }
      d[i] = cnt + 1;
      ans = max(ans, d[i]);
      fre[s[i] - 'a'] = cnt + 1;
    }
    cout << ans << '\n';
    for (auto i : d) {
      cout << i << " ";
    }
  }
  return 0;
}
