#include <bits/stdc++.h>
using namespace std;
int n;
char s[300100];
int d[300100];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  int t = strlen(s);
  int temp = 1;
  int temp2 = 0;
  char now = s[0];
  long long ans = 0;
  for (int i = 1; i < t; i++) {
    if (s[i] == now) {
      temp++;
    } else {
      d[++temp2] = temp;
      temp = 1;
      now = s[i];
      ans += 1ll * (d[temp2] - 1) * d[temp2] / 2;
    }
  }
  d[++temp2] = temp;
  int sum = 0;
  ans += 1ll * (d[temp2] - 1) * d[temp2] / 2;
  for (int i = 1; i < temp2; i++) {
    sum += d[i];
    ans += (n - sum - d[i + 1]);
    ans += 1ll * (d[i] - 1) * (n - sum - 1);
  }
  printf("%lld", ans);
  return 0;
}
