#include <bits/stdc++.h>
using namespace std;
int arr[300005];
int dp[26];
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    int x = s[i] - 'a';
    int val = 0;
    for (int j = x + 1; j < 26; j++) {
      val = max(val, dp[j]);
    }
    dp[x] = max(dp[x], val + 1);
    arr[i] = val + 1;
    cnt = max(cnt, val + 1);
  }
  cout << cnt << '\n';
  for (int i = 0; i < n; i++) {
    cout << arr[i] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
