#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
char s[maxn];
int main(void) {
  int n;
  scanf("%d", &n);
  long long res = (n - 1LL) * n / 2;
  scanf("%s", s);
  std::vector<long long> v;
  v.push_back(0);
  long long c = 0;
  for (int i = 0; i < n; i++) {
    if (i && s[i] != s[i - 1]) {
      v.push_back(c);
      c = 1;
    } else {
      c++;
    }
  }
  v.push_back(c);
  v.push_back(0);
  for (int i = 1; i + 1 < v.size(); i++) {
    res -= v[i - 1] + v[i + 1];
  }
  res += v.size() - 3;
  printf("%lld\n", res);
  return 0;
}
