#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    char t;
    cin >> t;
    int a = t - 'a';
    v.push_back(a);
  }
  int mx = -1, count = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (v[i] > mx) {
      mx = v[i];
      count++;
    }
  }
  vector<int> ans(n);
  map<int, int> colo;
  mx = -1;
  vector<int> alfa(26, 0);
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = v[i] + 1; j < 26; j++) {
      cnt = max(cnt, alfa[j]);
    }
    ans[i] = cnt + 1;
    alfa[v[i]] = cnt + 1;
    count = max(count, cnt + 1);
    mx = max(v[i], mx);
  }
  cout << count << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
