#include using namespace std; template struct binary_indexed_tree{ int N; vector BIT; binary_indexed_tree(int N): N(N), BIT(N + 1, 0){ } void add(int i, T x){ i++; while (i <= N){ BIT[i] += x; i += i & -i; } } T sum(int i){ T ans = 0; while (i > 0){ ans += BIT[i]; i -= i & -i; } return ans; } T sum(int L, int R){ return sum(R) - sum(L); } }; int main(){ int n; cin >> n; string s; cin >> s; vector cnt(26, 0); for (int i = 0; i < 26; i++){ cnt[s[i] - 'A']++; } binary_indexed_tree BIT(n); for (int i = 0; i < n; i++){ BIT.add(i, 1); } int ans = 0; int sh = 0; while (true){ int c1 = cnt[(26 - sh) % 26] + cnt[(28 - sh) % 26] + cnt[(32 - sh) % 26] + cnt[(45 - sh) % 26]; if (c1 == 0){ break; } int tv = 0, fv = n; while (fv - tv > 1){ int mid = (tv + fv) / 2; if (BIT.sum(mid + 1) <= c1){ tv = mid; } else { fv = mid; } } BIT.add(tv, -1); int t = s[tv] - 'A'; cnt[t]--; sh += cnt[t]; sh %= 26; ans++; } cout << ans << endl; }