#include <bits/stdc++.h>
using namespace std;
const string yno[2] = {"No\n", "Yes\n"};
void process() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> ans(n);
  string t;
  for (int i = 0; i <= n - 1; i++) {
    pair<int, int> tmp;
    for (int j = 0; j <= (int)t.size() - 1; j++) {
      if (t[j] <= s[i]) {
        tmp = max(tmp, pair<int, int>(t[j], j));
      }
    }
    if (tmp.first) {
      t[tmp.second] = s[i];
      ans[i] = tmp.second + 1;
    } else {
      t.push_back(s[i]);
      ans[i] = t.size();
    }
  }
  cout << t.size() << "\n";
  for (int i : ans) cout << i << ' ';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  process();
  return 0;
}
