#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long n, i, j, k;
  cin >> n;
  string a;
  cin >> a;
  for (i = 1; i < n; i++) {
    if (a[i - 1] != a[i]) break;
  }
  k = 0;
  for (; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      k++;
    }
  }
  reverse(a.begin(), a.end());
  for (i = 1; i < n; i++) {
    if (a[i - 1] != a[i]) break;
  }
  for (; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      k++;
    }
  }
  for (i = 1; i < n; i++)
    if (a[i - 1] != a[i]) k++;
  j = n * (n - 1) / 2;
  cout << j - k;
  return 0;
}
