#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<char> A;
  A.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  vector<vector<int>> dp;
  dp.resize(n);
  for (int i = 0; i < n; i++) {
    dp[i].assign(26, 0);
  }
  dp[0][A[0] - 97] = 1;
  for (int i = 1; i < n; i++) {
    int a = A[i] - 97;
    int temp = 1;
    for (int j = 25; j > a; j--) {
      temp = max(temp, dp[i - 1][j] + 1);
    }
    for (int j = 0; j < 26; j++) {
      if (j == a) {
        dp[i][j] = temp;
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  int temp = 0;
  for (int i = 0; i < 26; i++) {
    temp = max(temp, dp[n - 1][i]);
  }
  cout << temp << endl;
  for (int i = 0; i < n; i++) {
    int a = A[i] - 97;
    cout << dp[i][a] << " ";
  }
  cout << endl;
  return 0;
}
