#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int segtree[4 * 200005];
vector<pair<int, int> > vec;
int a[200005];
void update(int node, int start, int end, int idx, int val) {
  if (start > end || idx > end || idx < start) return;
  if (start == end) {
    segtree[node] = val;
    return;
  }
  int mid = (start + end) / 2;
  update(2 * node, start, mid, idx, val);
  update(2 * node + 1, mid + 1, end, idx, val);
  segtree[node] = max(segtree[2 * node], segtree[2 * node + 1]);
}
int query(int node, int start, int end, int l, int r) {
  if (start > end || r < start || l > end) return 0;
  if (l <= start && end <= r) return segtree[node];
  int mid = (start + end) / 2;
  return max(query(2 * node, start, mid, l, r),
             query(2 * node + 1, mid + 1, end, l, r));
}
int main() {
  memset(segtree, 0, sizeof segtree);
  cin >> n >> s;
  for (int i = 0; i < n; i++) {
    vec.push_back(pair<int, int>(s[i] - 'a', i));
  }
  sort(vec.begin(), vec.end());
  int max_color = 0;
  for (int i = 0; i < n; i++) {
    char ch = vec[i].first + 'a';
    int idx = vec[i].second;
    int color = query(1, 0, n - 1, idx, n - 1) + 1;
    a[idx] = color;
    update(1, 0, n - 1, idx, color);
    max_color = max(max_color, color);
  }
  cout << max_color << endl;
  for (int i = 0; i < n; i++) {
    if (i != 0) cout << " ";
    cout << a[i];
  }
  cout << "\n";
  return 0;
}
