#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
const int N = 2e5 + 1;
int n, mx[26], a[N], dp[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char c;
    cin >> c;
    a[i] = c - 'a';
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    for (int j = a[i] + 1; j < 26; j++) dp[i] = max(dp[i], mx[j] + 1);
    mx[a[i]] = max(mx[a[i]], dp[i]);
  }
  cout << *max_element(dp + 1, dp + 1 + n) << '\n';
  for (int i = 1; i <= n; i++) cout << dp[i] << ' ';
  return 0;
}
