#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N];
int dp[26];
int ans[N];
int main() {
  int n;
  string str;
  cin >> n >> str;
  fill(dp, dp + 26, 'a' - 1);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) {
      if (str[i] >= dp[j]) {
        ans[i] = j;
        dp[j] = str[i];
        break;
      }
    }
  }
  int nColor = 0;
  for (int i = 0; i < 26; ++i) {
    if (dp[i] != 'a' - 1) ++nColor;
  }
  cout << nColor << endl;
  for (int i = 0; i < n; ++i) {
    cout << ans[i] + 1 << " ";
  }
  cout << endl;
  return 0;
}
