#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1000;
char s[maxn];
int vis[30];
int ans[maxn];
set<int> se;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  cin >> s + 1;
  for (int i = 1; i <= N; i++) {
    int c = s[i] - 'a';
    int color = 1;
    for (int j = c + 1; j < 26; j++) {
      color = max(color, vis[j] + 1);
    }
    ans[i] = color;
    vis[c] = color;
    se.insert(color);
  }
  cout << se.size() << endl;
  for (int i = 1; i <= N; i++) cout << ans[i] << ' ';
  return 0;
}
