#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
vector<int> cand;
int prime[1000005];
void SieveOfEratosthenes(int n) {
  memset(prime, 0, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == 0) {
      for (int i = p * p; i <= n; i += p) prime[i] = p;
    }
  }
}
long long power(long long x, long long y) {
  long long res = 1ll;
  x = x % 1000000007;
  if (x == 0ll) return 0;
  while (y > 0ll) {
    if (y & 1ll) res = (res * x) % 1000000007;
    y = y >> 1ll;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long add(long long x, long long y) {
  x += y;
  while (x >= 1000000007) x -= 1000000007;
  while (x < 0) x += 1000000007;
  return x;
}
long long mul(long long x, long long y) { return (x * 1ll * y) % 1000000007; }
long long binpow(long long x, long long y) {
  long long z = 1ll;
  while (y) {
    if (y & 1) z = mul(z, x);
    x = mul(x, x);
    y >>= 1ll;
  }
  return z;
}
long long inv(long long x) { return binpow(x, 1000000007 - 2); }
long long divide(long long x, long long y) { return mul(x, inv(y)); }
long long fact[1000001];
void precalc() {
  fact[0] = 1;
  for (long long i = 1; i < 1000001; i++) fact[i] = mul(fact[i - 1], i);
}
long long C(long long n, long long k) {
  if (n == 0) return 1;
  return divide(fact[n], mul(fact[k], fact[n - k]));
}
long long sub(long long A, long long B) {
  return (A - B + 1000000007) % 1000000007;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(5);
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    string s;
    cin >> s;
    long long tot = (n * (n - 1)) / 2;
    vector<long long> v;
    long long len = 1;
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1])
        len++;
      else {
        v.push_back(len);
        len = 1;
      }
    }
    v.push_back(len);
    if (v.size() == 1) {
      cout << tot << "\n";
      return 0;
    }
    long long sub = 0;
    for (int i = 0; i < v.size(); i++) {
      if (i == 0 || i == (v.size() - 1))
        sub += v[i];
      else
        sub += 2 * v[i];
    }
    sub -= (v.size() - 1);
    cout << (tot - sub) << "\n";
  }
  return 0;
}
