#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> ans(n, 0);
  ans[0] = 1;
  map<char, int> biggest;
  biggest[s[0]] = 1;
  char largest_so_far = s[0];
  for (int i = 1; i < n; i++) {
    if (largest_so_far <= s[i]) {
      biggest[s[i]] = max(biggest[s[i]], 1);
    } else {
      int needed = 1;
      for (char c = s[i] + 1; c <= 'z'; c++) {
        if (biggest.count(c)) {
          needed = max(biggest[c] + 1, needed);
        }
      }
      biggest[s[i]] = needed;
    }
    ans[i] = biggest[s[i]];
    largest_so_far = max(largest_so_far, s[i]);
  }
  int maxe = 0;
  for (auto &x : ans) {
    maxe = max(maxe, x);
  }
  cout << maxe << '\n';
  for (auto &x : ans) {
    cout << x << ' ';
  }
}
