#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unrool-loops")
#pragma GCC optimize("no-stack-limit")
using namespace std;
const long long M = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<long long>> indexes(27);
  for (long long i = 0; i < n; i++) {
    indexes[s[i] - 'a'].push_back(i);
  }
  vector<pair<long long, long long>> rebra;
  vector<long long> ans(27, 1);
  vector<vector<long long>> graph(27);
  for (long long c = 0; c < 26; c++) {
    for (long long p = c + 1; p < 26; p++) {
      if (!indexes[c].empty() && !indexes[p].empty() &&
          indexes[c].back() > indexes[p].front()) {
        rebra.push_back({p, c});
        graph[p].push_back(c);
        graph[c].push_back(p);
      }
    }
  }
  long long color = 1;
  vector<bool> used(n, false);
  for (long long i = 0; i < n; i++) {
    if (!used[i]) {
      long long j = i;
      long long cnt = 0;
      while (j < n) {
        cnt++;
        ans[j] = cnt;
        used[j] = true;
        long long next = n;
        for (char c2 = 0; c2 < s[j] - 'a'; c2++) {
          if (!indexes[c2].empty() && indexes[c2].back() > i) {
            long long start =
                upper_bound(indexes[c2].begin(), indexes[c2].end(), i) -
                indexes[c2].begin();
            for (long long s2 = start; s2 < indexes[c2].size(); s2++) {
              ans[indexes[c2][s2]] = cnt + 1;
              used[indexes[c2][s2]] = true;
              used[indexes[c2][s2]] = true;
            }
            next = min(next, indexes[c2][start]);
          }
        }
        j = next;
      }
      color = max(color, cnt);
    }
  }
  if (color > 26) {
    color = 26;
  }
  for (long long _ = 0; _ < (1e7 / 26 / 26); _++) {
    for (auto p : rebra) {
      if (ans[p.first] == ans[p.second]) {
        long long lol = p.first;
        if (rand() % 2 == 1) {
          lol = p.second;
        }
        bitset<277> kek;
        for (auto l : graph[lol]) {
          kek[ans[l]] = true;
        }
        bool f = false;
        for (long long y = 1; y <= color; y++) {
          if (!kek[y]) f = true;
        }
        if (f) {
          for (long long _ = 0; _ < 100; _++) {
            long long uu = rand() % color + 1;
            if (!kek[uu]) {
              ans[lol] = uu;
              break;
            }
          }
        } else {
          ans[lol] = 1 + rand() % color;
        }
      }
    }
  }
  cout << color << '\n';
  for (long long i = 0; i < n; i++) cout << ans[s[i] - 'a'] << ' ';
}
