#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int MAXN = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
void file() {}
signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  ;
  int n, num = 0;
  string str;
  vector<int> ans, vec;
  cin >> n >> str;
  reverse(str.begin(), str.end());
  for (int i = 0; i < n; i++) {
    int pos = lower_bound(vec.begin(), vec.end(), str[i]) - vec.begin();
    ans.push_back(pos + 1);
    num = max(num, pos + 1);
    if (pos < vec.size())
      vec[pos] = str[i];
    else
      vec.push_back(str[i]);
  }
  cout << num << "\n" << flush;
  reverse(ans.begin(), ans.end());
  for (auto it : ans) cout << it << " ";
  cout << "\n" << flush;
  return 0;
}
