#include <bits/stdc++.h>
using namespace std;
int C(char c) { return c - 'a'; }
int ans[200007], dp[30];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int biggu = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 26; j > C(s[i]); j--) {
      ans[i] = max(ans[i], dp[j] + 1);
    }
    dp[C(s[i])] = max(dp[C(s[i])], ans[i]);
    biggu = max(biggu, ans[i]);
  }
  cout << biggu << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
