#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.sync_with_stdio(false), cin.tie(nullptr);
  int n;
  string s;
  cin >> n >> s;
  vector<int> res(n, 1), col(26, 1), vis(26, false);
  auto check = [&](int c) -> bool {
    for (int i = 0; i < c; i++) {
      if (vis[i] && col[i] == col[c]) {
        return true;
      }
    }
    return false;
  };
  for (int i = n - 1; i >= 0; i--) {
    int x = s[i] - 'a';
    while (check(x)) {
      ++col[x];
    }
    res[i] = col[x], vis[x] = true;
  }
  cout << *max_element(res.begin(), res.end()) << "\n";
  for (int i = 0; i < n; i++) {
    cout << res[i] << " \n"[i + 1 == n];
  }
}
