#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
signed main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    long long cnt = 1;
    while (s[i] == s[i + 1]) {
      cnt++;
      i++;
    }
    v.push_back(cnt);
  }
  long long ans = n * (n - 1) / 2;
  long long sum = 0;
  for (long long i = 0; i < v.size(); i++) {
    if (i != 0) {
      sum += v[i - 1] - 1;
    }
    if (i != v.size() - 1) {
      sum += v[i + 1];
    }
  }
  long long res = ans - sum;
  cout << res << endl;
  return 0;
}
