#include <bits/stdc++.h>
using namespace std;
bool check(vector<long long> &v, string &s, long long i) {
  if (v.size() == 0) {
    v.push_back(i);
    return true;
  }
  long long n = v.size();
  if (s[v[n - 1]] <= s[i]) {
    v.push_back(i);
    return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<long long> > col(27);
  for (int i = 0; i < n; i++) {
    for (long long j = 1; j <= 26; j++) {
      if (check(col[j], s, i)) {
        break;
      }
    }
  }
  long long ans = 0;
  for (long long i = 1; i <= 26; i++) {
    if (col[i].size() > 0) {
      ans++;
    }
  }
  cout << ans << endl;
  vector<long long> v(n);
  for (long long i = 1; i <= 26; i++) {
    for (long long j = 0; j < col[i].size(); j++) {
      v[col[i][j]] = i;
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << v[i] << " ";
  }
  return 0;
}
