#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> res(n);
  vector<int> dp(27, 0);
  for (int i = 0; i < n; i++) {
    int d = s[i] - 'a';
    for (int j = d + 1; j < 27; j++) dp[d] = max(dp[d], dp[j] + 1);
    res[i] = dp[d];
  }
  cout << *max_element(res.begin(), res.end()) << endl;
  for (int i = 0; i < n; i++) cout << res[i] << " ";
  cout << endl;
  return 0;
}
