#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  string ans;
  for (int i = n - 1; i >= 0; i--) {
    auto it = lower_bound(ans.begin(), ans.end(), s[i]);
    if (it == ans.end())
      ans += s[i];
    else {
      int ind = it - ans.begin();
      ans[ind] = s[i];
    }
  }
  int sz = ans.size();
  cout << sz << endl;
  ans = "";
  vector<int> a(n);
  for (int i = n - 1; i >= 0; i--) {
    auto it = lower_bound(ans.begin(), ans.end(), s[i]);
    if (it == ans.end()) {
      ans += s[i];
      a[i] = ans.size();
    } else {
      int ind = it - ans.begin();
      ans[ind] = s[i];
      a[i] = ind + 1;
    }
  }
  for (int elem : a) {
    cout << elem << " ";
  }
  return 0;
}
