#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, ans[maxn], res[30];
char a[maxn];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    int Max = 0;
    for (int j = a[i] - 'a' + 1; j <= 26; ++j) Max = max(Max, res[j]);
    res[a[i] - 'a'] = Max + 1;
    ans[i] = res[a[i] - 'a'];
  }
  int Ans = 0;
  for (int i = 0; i <= 26; ++i) Ans = max(Ans, res[i]);
  cout << Ans << endl;
  for (int i = 1; i <= n; ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
