#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 20, MAXM = 124, SZ = 26;
const long long inf = 1e9 + 100, mod = 1e9 + 7;
int find_lds(vector<int>& a, string& s) {
  int n = s.length();
  vector<int> d(n, -inf);
  int mx = 0;
  for (int j = 0; j < n; ++j) {
    int l = -1, r = n - 1;
    int x = s[j] - 'a';
    while (r - l > 1) {
      int m = l + r >> 1;
      if (d[m] > x)
        l = m;
      else
        r = m;
    }
    d[r] = x;
    a[j] = r + 1;
    mx = max(mx, r + 1);
  }
  return mx;
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  cout << find_lds(a, s) << '\n';
  for (int ai : a) cout << ai << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) solve();
}
