#include <bits/stdc++.h>
using namespace std;
void yn(bool truth) {
  if (truth)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
}
long long cl(long long x, long long y) {
  if (x % y == 0)
    return x / y;
  else
    return x / y + 1;
}
void pri(vector<long long>& x) {
  for (long long(i) = 0; (i) < (x.size()); (i)++) {
    cout << x[i] << " ";
  }
  cout << '\n';
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> ans;
  vector<long long> a(26, 0);
  for (long long i = 0; i < n; i++) {
    long long x = s[i] - 'a';
    long long sv = 0;
    for (long long i = x + 1; i < 26; i++) {
      sv = max(sv, a[i]);
    }
    a[x] = max(a[x], sv + 1);
    ans.push_back(a[x]);
  }
  cout << *max_element(ans.begin(), ans.end()) << '\n';
  pri(ans);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  solve();
}
