#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long int> store;
  int cnt = 0;
  char c = s[0];
  for (int i = 0; i < n; i++) {
    if (c == s[i]) {
      cnt++;
    } else {
      store.push_back(cnt);
      cnt = 1;
      c = s[i];
    }
  }
  store.push_back(cnt);
  long long int ans = (n) * (n - 1) / 2;
  for (int i = 0; i < (long long int)store.size(); i++) {
    if (i > 0) ans -= store[i - 1] - 1;
    if (i < (long long int)store.size() - 1) ans -= store[i + 1];
  }
  cout << ans;
}
