#include <bits/stdc++.h>
using namespace std;
int arr[26];
int res[200000];
int main() {
  ios::sync_with_stdio(0);
  int n, m, ans = 0;
  string str;
  cin >> n >> str;
  for (int i = 0; i < n; i++) {
    m = 0;
    for (int j = str[i] - 'a' + 1; j < 26; j++)
      if (arr[j] > m) m = arr[j];
    m++;
    res[i] = m;
    arr[str[i] - 'a'] = m;
    if (m > ans) ans = m;
  }
  cout << ans << endl;
  for (int i = 0; i < n; i++) cout << res[i] << " ";
  return 0;
}
