#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 5;
int n, now;
char str[N];
int col[N];
multiset<pair<char, int> > s;
multiset<pair<char, int> >::iterator it;
int main() {
  scanf("%d", &n);
  scanf("%s", str + 1);
  for (int i = 1; i <= n; i++) {
    it = s.upper_bound({str[i], 0x3f3f3f3f});
    if (it != s.begin()) {
      it--;
      col[i] = it->second;
      s.insert({str[i], col[i]});
      s.erase(it);
    } else {
      col[i] = ++now;
      s.insert({str[i], col[i]});
    }
  }
  printf("%d\n", now);
  for (int i = 1; i <= n; i++) printf("%d ", col[i]);
  return 0;
}
