#include <bits/stdc++.h>
using namespace std;
long long M = (long long)1e9 + 1, t = 0;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long digits(long long n) { return floor(log10(n)) + 1; }
bool ispoweroftwo(long long x) { return x && (!(x & (x - 1))); }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  string s;
  cin >> n >> s;
  map<char, vector<vector<long long> > > m;
  vector<long long> v;
  v.push_back(0);
  m[s[0]].push_back(v);
  char x = s[0];
  set<char> ss;
  for (long long i = 1; i < n; i++) {
    ss.insert(s[i]);
    vector<long long> xx;
    if (s[i] < x) {
      xx.push_back(i);
      m[s[i]].push_back(xx);
    } else {
      long long ff = 1;
      for (char c = s[i]; c >= 'a'; c--) {
        long long sz = m[c].size();
        if (sz > 0) {
          if (s[i] == c)
            m[c][sz - 1].push_back(i);
          else {
            m[c][sz - 1].push_back(i);
            m[s[i]].push_back(m[c][sz - 1]);
            m[c].pop_back();
          }
          ff = 0;
          break;
        }
      }
      if (ff) {
        xx.push_back(i);
        m[s[i]].push_back(xx);
      }
    }
    x = min(x, s[i]);
  }
  vector<long long> ans(n);
  long long cl = 1;
  long long cnt = 0;
  ss.insert(s[0]);
  for (char cc : ss) {
    vector<vector<long long> > x = m[cc];
    for (vector<long long> y : x) {
      for (long long z : y) {
        ans[z] = cl;
      }
      cnt++;
      if (y.size() > 0) cl++;
    }
  }
  cout << cnt << endl;
  for (long long x : ans) cout << x << " ";
  cout << endl;
}
