#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void isprime() {
  long long n = 10000;
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true)
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long ans = n * (n - 1) >> 1, cur = s[0], cnt = 0;
    bool f = 1;
    for (long long i = 0; i < n; i++) {
      if (cur == s[i])
        cnt++;
      else {
        if (f) {
          f &= 0;
          ans -= cnt;
        } else
          ans -= 2 * cnt;
        cnt = 1;
        cur = s[i];
        ans++;
      }
    }
    if (!f) ans -= cnt;
    cout << ans;
  }
  return 0;
}
