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