#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
int alfa[26];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  memset(alfa, 0, sizeof(alfa));
  int nn;
  cin >> nn;
  string second;
  cin >> second;
  vector<int> ans;
  int mx = 0;
  for (int i = 0; i < nn; i++) {
    set<int> st;
    for (int j = second[i] - 'a' + 1; j <= 'z' - 'a'; j++) st.insert(alfa[j]);
    for (int j = 1; j <= 26; j++)
      if (st.find(j) == st.end()) {
        ans.push_back(alfa[second[i] - 'a'] = j);
        break;
      }
  }
  for (int i = 0; i <= 'z'; i++) mx = max(mx, alfa[i]);
  cout << mx << endl;
  for (int i = 0; i < nn; i++) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}
