#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> dp(n + 1, -INF), a(n);
  for (long long &x : a) {
    char c;
    cin >> c;
    x = c - 'a';
  }
  dp[0] = INF;
  vector<long long> ans(n, 1);
  for (long long i = 0; i < n; i++) {
    long long val = a[i];
    long long l = 0;
    long long r = n;
    while (r > l + 1) {
      long long mid = (l + r) / 2;
      if (val > dp[mid])
        r = mid;
      else
        l = mid;
    }
    if (val < dp[r - 1]) {
      dp[r] = val;
      ans[i] = r;
    } else
      ans[i] = r - 1;
  }
  long long p = 1;
  for (long long i = 1; i <= n; i++) {
    if (dp[i] != -INF) {
      p = max(p, i);
    }
  }
  cout << p << endl;
  for (long long x : ans) cout << x << ' ';
  return 0;
}
