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