#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
long long used[200005], ans[200005], p[26];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> s;
  long long cnt = 0;
  memset(p, -1, sizeof(p));
  for (long long i = 0; i < n; i++) {
    long long pos = s[i] - 'a';
    long long prev = -1;
    for (long long j = pos; j >= 0; j--) {
      if (p[j] != -1) {
        prev = p[j];
        break;
      }
    }
    if (prev == -1) {
      cnt++;
      ans[i] = cnt;
    } else {
      p[s[prev] - 'a'] = -1;
      ans[i] = ans[prev];
    }
    p[pos] = i;
  }
  cout << cnt << endl;
  for (long long i = 0; i < n; i++) cout << ans[i] << ' ';
  cout << endl;
}
