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