#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  set<int> col[26];
  vector<int> ans;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    set<int> used;
    for (int j = s[i] - 'a' + 1; j < 26; j++)
      for (int num : col[j]) used.insert(num);
    int newCol = 1;
    while (used.count(newCol)) newCol++;
    col[s[i] - 'a'].insert(newCol);
    ans.push_back(newCol);
    cnt = max(cnt, newCol);
  }
  cout << cnt << "\n";
  for (int i : ans) cout << i << " ";
  return 0;
}
