#include <bits/stdc++.h>
using namespace std;
char s[301010];
int n;
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int c = 1;
    while (s[i] == s[i + 1] && i < n - 1) i++, c++;
    a.push_back(c);
  }
  long long ans = 1LL * n * (n - 1) / 2;
  for (int i = 0; i < a.size() - 1; i++) ans -= (a[i] + a[i + 1] - 1);
  printf("%lld\n", ans);
  return 0;
}
