#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
char str[MAXN];
int ans[MAXN];
int num[30];
int main() {
  int n;
  while (cin >> n) {
    memset(ans, 0, sizeof(ans));
    memset(num, 0, sizeof(num));
    cin >> (str + 1);
    int maxval = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= 26; j++) {
        if (str[i] >= num[j]) {
          ans[i] = j;
          num[j] = str[i];
          maxval = max(maxval, j);
          break;
        }
      }
    }
    cout << maxval << endl;
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
