#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v;
  long long num = 0;
  long long cur = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] != s[cur]) {
      cur = i;
      i--;
      v.push_back(num);
      num = 0;
    } else {
      num++;
    }
  }
  if (num != 0) {
    v.push_back(num);
  }
  long long bad = 0;
  for (long long i = 1; i < v.size(); i++) {
    bad += v[i] + v[i - 1] - 1;
  }
  cout << (n * (n - 1)) / 2 - bad;
  return 0;
}
