#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> maxdp(26);
  vector<int> dp(n, 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]);
  }
  cout << *max_element(maxdp.begin(), maxdp.end()) << endl;
  for (auto x : dp) cout << x << " ";
  return 0;
}
