#include <bits/stdc++.h>
using namespace std;
long long powermod(long long a, long long b, long long c) {
  long long ans = 1, tempans = a % c;
  while (b > 0) {
    if (b & 1 == 1) {
      ans = (ans * tempans) % c;
    }
    tempans = (tempans * tempans) % c;
    b = b >> 1;
  }
  return ans;
}
long long modinverse(long long a, long long m) { return powermod(a, m - 2, m); }
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v;
  for (long long i = 0; i < n;) {
    long long count = 1;
    i++;
    while (i < n && s[i] == s[i - 1]) {
      count++;
      i++;
    }
    v.push_back(count);
  }
  long long ans = (n * (n - 1)) / 2;
  for (long long i = 0; i < v.size() - 1; i++) {
    ans -= (v[i] + v[i + 1] - 1);
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t = 1;
  long long count = 1;
  while (t--) {
    solve();
    count++;
  }
}
