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