#include <bits/stdc++.h>
namespace IPT {
const int L = 1000000;
char buf[L], *front = buf, *end = buf;
char GetChar() {
  if (front == end) {
    end = buf + fread(front = buf, 1, L, stdin);
    if (front == end) return -1;
  }
  return *(front++);
}
}  // namespace IPT
template <typename T>
inline void qr(T &x) {
  char ch = IPT::GetChar(), lst = ' ';
  while ((ch > '9') || (ch < '0')) lst = ch, ch = IPT::GetChar();
  while ((ch >= '0') && (ch <= '9'))
    x = (x << 1) + (x << 3) + (ch ^ 48), ch = IPT::GetChar();
  if (lst == '-') x = -x;
}
namespace OPT {
char buf[120];
}
template <typename T>
inline void qw(T x, const char aft, const bool pt) {
  if (x < 0) {
    x = -x, putchar('-');
  }
  int top = 0;
  do {
    OPT::buf[++top] = static_cast<char>(x % 10 + '0');
  } while (x /= 10);
  while (top) putchar(OPT::buf[top--]);
  if (pt) putchar(aft);
}
const int maxn = 200005;
int n, ans;
char S[maxn];
int frog[maxn], pos[30];
int main() {
  ;
  scanf("%d\n%s", &n, S + 1);
  for (int i = 1; i <= n; ++i) {
    for (int k = S[i] + 1 - 'a'; k < 26; ++k)
      if (frog[pos[k]] > frog[i]) {
        frog[i] = frog[pos[k]];
      }
    ans = std::max(ans, ++frog[i]);
    pos[S[i] - 'a'] = i;
  }
  qw(ans, '\n', true);
  for (int i = 1; i < n; ++i) {
    qw(frog[i], ' ', true);
  }
  qw(frog[n], '\n', true);
  return 0;
}
