#include <bits/stdc++.h>
using namespace std;
void fun() {
  int n;
  string s;
  cin >> n >> s;
  vector<pair<char, int> > v;
  for (int i = 0; i < n; i++) v.push_back({s[i], i});
  sort((v).begin(), (v).end());
  vector<int> ans(n, 0);
  map<int, int> m;
  m[v[0].second] = 1;
  int col = 1;
  ans[v[0].second] = 1;
  for (int i = 1; i < n; i++) {
    auto it = m.lower_bound(v[i].second);
    if (it == m.begin()) {
      col++;
      m[v[i].second] = col;
      ans[v[i].second] = col;
    } else {
      it--;
      int y = it->second;
      m.erase(it);
      m[v[i].second] = y;
      ans[v[i].second] = y;
    }
  }
  cout << col << '\n';
  for (auto i : ans) cout << i << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  ;
  int t = 1;
  while (t--) {
    fun();
  }
}
