#include <bits/stdc++.h>
using namespace std;
int n;
char s[200010];
char s_end[30];
int ans[200010];
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s + 1;
  memset(s_end, 0, sizeof(s_end));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      if (s[i] >= s_end[j]) {
        s_end[j] = s[i];
        ans[i] = j;
        break;
      }
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    res = max(res, ans[i]);
  }
  cout << res << endl;
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
