#include <bits/stdc++.h>
using namespace std;
long long ans, sum;
int n, cnt, cur;
char s[300005];
int x[300005];
int main() {
  scanf("%d%s", &n, s);
  for (int i = 0; i < n; i++) {
    cnt = 1;
    while (s[i] == s[i + 1]) {
      cnt++;
      i++;
    }
    x[cur++] = cnt;
  }
  ans = (long long)n * (n - 1) / 2;
  for (int i = 0; i < cur; i++) {
    if (i != 0) {
      sum += x[i - 1] - 1;
    }
    if (i != cur - 1) {
      sum += x[i + 1];
    }
  }
  printf("%lld\n", ans - sum);
}
