#include <bits/stdc++.h>
using namespace std;
long long tab[100002];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  string slo;
  cin >> slo;
  long long wyn = (n - 1) * n / 2;
  long long si = 1, gr = 1;
  for (long long i = 1; i < n; i++) {
    if (slo[i] == slo[i - 1])
      si++;
    else {
      wyn -= si;
      gr++;
      si = 1;
    }
  }
  reverse(slo.begin(), slo.end());
  si = 1;
  for (long long i = 1; i < n; i++) {
    if (slo[i] == slo[i - 1])
      si++;
    else {
      wyn -= si - 1;
      gr++;
      si = 1;
    }
  }
  cout << wyn;
}
