#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = (n * (n - 1)) / 2;
  long long l = 0, r = n - 1;
  while (s[l] == s[0]) l++;
  while (s[r] == s[n - 1]) r--;
  r = n - 1 - r;
  long long num = 0;
  for (long long i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      num++;
    }
  }
  cout << ans - (2 * n) + l + r + num;
  return 0;
}
