#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long N = 1e6 + 7;
const long long mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, ans = 0;
  cin >> n;
  ans = (n * (n - 1)) / 2;
  string s;
  cin >> s;
  for (long long x = 0; x < 2; x++) {
    long long cnt = 1;
    for (long long i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) {
        cnt++;
      } else {
        ans -= cnt - x;
        cnt = 1;
      }
    }
    reverse(s.begin(), s.end());
  }
  cout << ans;
}
