#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int ans[200200];
int num[200];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s;
  ans[0] = 1;
  num[s[0]] = 1;
  int now = 1;
  int temp = 1;
  int cnt = 1;
  for (int i = 1; i < (int)s.size(); i++) {
    int maxi = 0, ind = -1;
    for (char j = 'z'; j > s[i]; j--) {
      if (num[j] > maxi) {
        maxi = num[j];
        ind = j - 'a';
      }
    }
    num[s[i]] = maxi + 1;
    ans[i] = maxi + 1;
    cnt = max(cnt, maxi + 1);
  }
  cout << cnt << '\n';
  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
}
