#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
  return os << "(" << x.first << "," << x.second << ")";
}
char str[200005];
int main() {
  int n;
  scanf("%d%s", &n, str);
  vector<vector<int>> cnt(26);
  int ans = 0;
  vector<int> col(n);
  for (int i = 0; i < n; ++i) {
    int c = str[i] - 'a';
    bool found = false;
    for (int j = c; j >= 0; --j) {
      if (!cnt[j].empty()) {
        auto b = cnt[j].back();
        cnt[j].pop_back();
        cnt[c].push_back(i);
        col[i] = col[b];
        found = true;
        break;
      }
    }
    if (!found) {
      col[i] = ++ans;
      cnt[c].push_back(i);
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < n; ++i) printf("%d ", col[i]);
}
