#include <bits/stdc++.h>
using namespace std;
int T;
long long a[200080];
long long b[200080];
string s;
long long n;
long long ans;
long long now;
long long num = 0;
int main() {
  cin >> n;
  cin >> s;
  ans = (n * (n - 1)) / 2;
  now = 0;
  for (int i = 1; i <= n - 1; i++) {
    if (s[i] == s[i - 1]) continue;
    num += 1;
    ans -= (i - now);
    now = i;
  }
  now = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    if (s[i] == s[i + 1]) continue;
    ans -= (now - i);
    now = i;
  }
  cout << ans + num;
  return 0;
}
