#include <bits/stdc++.h>
using namespace std;
void mainSolve() {
  vector<vector<pair<char, long long int>>> ans(26);
  unordered_map<long long int, long long int> cnt;
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (cnt[j] == 0) {
        ans[j].push_back({s[i], i});
        ++cnt[j];
        break;
      }
      if (s[i] >= ans[j].back().first) {
        ans[j].push_back({s[i], i});
        ++cnt[j];
        break;
      }
    }
  }
  vector<long long int> result(n, 0);
  long long int max_len = 1;
  for (int i = 0; i < 26; i++) {
    long long int len = ans[i].size();
    if (len == 0) continue;
    for (int j = 0; j < len; j++) result[ans[i][j].second] = (i + 1);
    max_len = (i + 1);
  }
  cout << max_len << '\n';
  for (long long int i = 0; i < result.size(); ++i) cout << result[i] << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    mainSolve();
  }
  return 0;
}
