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