#include <bits/stdc++.h>
using namespace std;
void Solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = n * (n - 1) / 2;
  char last = s[0];
  long long cnt = 1;
  vector<long long> v;
  for (long long i = 1; i < n; i++) {
    if (s[i] == last) {
      cnt++;
    } else {
      v.push_back(cnt);
      last = s[i];
      cnt = 1;
    }
  }
  v.push_back(cnt);
  for (long long i = 1; i < v.size(); i++) {
    ans -= v[i] + v[i - 1] - 1;
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Solve();
  return 0;
}
