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