#include <bits/stdc++.h>
using namespace std;
int N, ans;
vector<int> lis, color;
char a;
int main() {
  scanf("%d", &N);
  getchar();
  for (int i = 0; i < N; i++) {
    scanf("%c", &a);
    int num = -(int)(a - 'a');
    if (i == 0 || lis[ans - 1] < num) {
      ans++;
      lis.push_back(num);
      color.push_back(ans);
    } else {
      auto it = lower_bound(lis.begin(), lis.end(), num);
      int c = (it - lis.begin()) + 1;
      *it = num;
      color.push_back(c);
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < N; i++) printf("%d ", color[i]);
  return 0;
}
