#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  scanf("%lld", &n);
  string s;
  cin >> s;
  long long int ans = (n + 1) * n;
  ans /= 2;
  long long int not_good = n;
  for (long long int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) continue;
    long long int l = 0, r = 0;
    while (1) {
      if (l == i) break;
      if (s[i - 1] != s[i - 1 - l]) break;
      l++;
    }
    while (1) {
      if (i + r >= n) break;
      if (s[i] != s[i + r]) break;
      r++;
    }
    not_good += l + r - 1;
  }
  ans -= not_good;
  printf("%lld\n", ans);
}
