#include <bits/stdc++.h>
using namespace std;
long long int i, j, k, n, n1, n2, n3, n4, m, a, b, c, d, x, y, z,
    cnt = 0, cnt1 = 0, flag = 0, flag1 = 0, sum = 0, sum1 = 0, ans = 0,
    ans1 = 0, mn = INT_MAX, mx = INT_MIN;
void ashwani() {}
int main() {
  ashwani();
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  string s1;
  cin >> n;
  cin >> s1;
  n = s1.length();
  vector<long long int> v1;
  char ch = s1[0];
  cnt = 1;
  for (i = 1; i < n; i++) {
    if (s1[i] == ch)
      cnt++;
    else {
      v1.push_back(cnt);
      ch = s1[i];
      cnt = 1;
    }
  }
  v1.push_back(cnt);
  cnt = 0;
  for (i = 0; i < v1.size() - 1; i++) {
    if (v1[i] == 1 && v1[i + 1] != 1)
      cnt += v1[i + 1];
    else if (v1[i] != 1 && v1[i + 1] == 1)
      cnt += v1[i];
    else if (v1[i] != 1 && v1[i + 1] != 1)
      cnt += v1[i] + v1[i + 1] - 1;
    else if (v1[i] == 1 && v1[i + 1] == 1)
      cnt++;
  }
  long long int ttl = (n * (n - 1)) / 2;
  ans = ttl - cnt;
  cout << ans << "\n";
  ans = 0;
  cnt = 0;
  return 0;
}
