#include <bits/stdc++.h>
using namespace std;
int saida[200010];
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  string s, s1, s2;
  cin >> s;
  int ans = 1;
  vector<bool> ocorreu(26, false);
  vector<int> cores(26, 1);
  for (int i = 0; i < n; ++i) {
    int c = s[i] - 'a';
    ocorreu[c] = true;
    for (int j = c + 1; j < 26; j++)
      if (ocorreu[j]) cores[c] = max(cores[c], cores[j] + 1);
    saida[i] = cores[c];
    ans = max(ans, cores[c]);
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) {
    cout << saida[i];
    if (i < n - 1) cout << " ";
  }
  cout << endl;
  return 0;
}
