#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string se;
  cin >> se;
  std::vector<long long> dp(n, 1);
  std::vector<long long> chardp(26, 0);
  for (long long i = 0; i < n; ++i) {
    for (long long j = se[i] - 'a' + 1; j < 26; ++j)
      dp[i] = max(dp[i], chardp[j] + 1);
    chardp[se[i] - 'a'] = max(dp[i], chardp[se[i] - 'a']);
  }
  cout << *max_element(chardp.begin(), chardp.end()) << "\n";
  for (long long i = 0; i < n; ++i) cout << dp[i] << " ";
  return 0;
}
