#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  string s;
  cin >> n >> s;
  long long int total;
  if (n % 2 == 0)
    total = (n / 2) * (n - 1);
  else
    total = (n) * ((n - 1) / 2);
  int st = 1;
  int temp = 0;
  std::vector<int> v;
  while (temp < n) {
    if (s[temp] == s[st])
      st++;
    else {
      v.push_back(st - temp);
      temp = st;
      st++;
    }
  }
  long long int ans = 0;
  for (int i = 0; i < v.size() - 1; i++) {
    ans += (long long int)(v[i] + v[i + 1] - 1);
  }
  ans = total - ans;
  cout << ans << endl;
}
