#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const long long LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 9;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  string s;
  int n;
  cin >> n >> s;
  vector<int> ans, color(n);
  for (int i = 0; i < n; i++) {
    if (ans.empty())
      ans.push_back(s[i]), color[i] = ans.size() - 1;
    else {
      bool ok = true;
      for (int j = 0; j < ans.size(); j++) {
        if (ans[j] <= s[i]) {
          ans[j] = s[i];
          color[i] = j;
          ok = false;
          break;
        }
      }
      if (ok) {
        ans.push_back(s[i]);
        color[i] = ans.size() - 1;
      }
    }
  }
  cout << ans.size() << '\n';
  for (int a : color) cout << a + 1 << ' ';
  return 0;
}
