#include <bits/stdc++.h>
using namespace std;
void zanj0() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void out(vector<long long int>& v) {
  for (long long int i : v) {
    cout << i << " ";
  }
  cout << "\n";
}
void solve() {
  long long int n;
  cin >> n;
  long long int ans = 0;
  vector<long long int> ret(n);
  string s;
  cin >> s;
  vector<long long int> cnt(26);
  for (long long int i = n - 1; i >= 0; i--) {
    long long int idx = s[i] - 'a';
    long long int maxVal = 1;
    for (long long int j = idx - 1; j >= 0; j--) {
      maxVal = max(maxVal, 1 + cnt[j]);
    }
    cnt[idx] = maxVal;
    ret[i] = cnt[idx];
    ans = max(ans, ret[i]);
  }
  cout << ans << "\n";
  out(ret);
}
int32_t main() {
  zanj0();
  solve();
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
