#include <bits/stdc++.h>
using namespace std;
int n, Cnt, A;
int res[1000006], d[1000006];
char a;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  set<int> SET;
  SET.insert(0);
  SET.insert(100);
  cin >> n;
  d[0] = 1;
  Cnt = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a;
    A = a - 'a';
    auto it = lower_bound(SET.begin(), SET.end(), A);
    if (A < *it && it == SET.begin()) {
      SET.insert(A);
      d[A] = res[i] = ++Cnt;
      continue;
    } else if (A < *it)
      it--;
    d[A] = res[i] = d[*it];
    SET.erase(it);
    SET.insert(A);
  }
  cout << Cnt << "\n";
  for (int i = 1; i <= n; i++) cout << res[i] << " ";
}
