#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  string s;
  cin >> n >> s;
  vector<long long int> maxdp(26);
  vector<long long int> dp(n, 1);
  for (long long int i = 0; i < n; ++i) {
    for (long long int c = 25; c > s[i] - 'a'; --c) {
      dp[i] = max(dp[i], maxdp[c] + 1);
    }
    maxdp[s[i] - 'a'] = max(maxdp[s[i] - 'a'], dp[i]);
  }
  cout << *max_element(maxdp.begin(), maxdp.end()) << endl;
  for (long long int i = 0; i < n; ++i) cout << dp[i] << " ";
  cout << endl;
  return 0;
}
