#include <bits/stdc++.h>
using namespace std;
char c[200005];
struct stru {
  int i1, i2, col;
};
int ans[200005], n;
bool cmp(const stru &a, const stru &b) { return a.i1 < b.i1; }
string d;
bool verif(int m) {
  int v[2000005];
  for (int i = 1; i <= m; ++i) v[i] = 0;
  for (int i = 1; i <= n; ++i) {
    bool posi = 1;
    for (int j = 1; j <= m; ++j) {
      if (c[i] >= v[j]) {
        v[j] = c[i];
        ans[i] = j - 1;
        posi = 0;
        break;
      }
    }
    if (posi == 1) return 1;
  }
  return 0;
}
int main() {
  int x = 0, y = 0;
  cin >> n;
  cin.get();
  for (int i = 1; i <= n; ++i) cin.get(c[i]);
  int msk = 1 << 21, pos = 0;
  for (; msk; msk /= 2)
    if (200000 >= pos + msk && verif(pos + msk)) pos += msk;
  cout << pos + 1 << '\n';
  for (int i = 1; i <= n; ++i) cout << ans[i] + 1 << " ";
  return 0;
}
