#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = n * (n + 1) / 2;
  ans -= n;
  vector<int> v;
  for (long long i = 0; i < n;) {
    long long j = i;
    while (j < n && s[i] == s[j]) j++;
    v.push_back(j - i);
    i = j;
  }
  for (long long i = 0; i < v.size() - 1; i++) {
    long long x = v[i];
    long long y = v[i + 1];
    long long t = (x + y - 1);
    ans -= t;
  }
  cout << ans << "\n";
  return 0;
}
