#include <bits/stdc++.h>
using namespace std;
const long long sz = 200005;
long long mod = 1e9 + 7;
long long n, t;
vector<long long> BIT(sz, 0);
void Update(long long in, long long x) {
  for (long long i = in; i < sz; i += i & (-i)) BIT[i] += 1;
}
long long Query(long long in) {
  long long ans = 0;
  for (long long i = in; i >= 1; i -= i & (-i)) ans += BIT[i];
  return ans;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second) return (a.second < b.second);
  return (a.first > b.first);
}
vector<long long> fac(sz, 1);
void init() {
  for (long long i = 1; i < sz; i++) fac[i] = (fac[i - 1] * i) % mod;
}
long long Power(long long a, long long b) {
  if (a == 0) return 0;
  if (b == 0) return 1;
  long long ans = Power((a * a) % mod, b / 2);
  if (b & 1) return (a * ans) % mod;
  return ans % mod;
}
long long Inv(long long a) { return Power(a, mod - 2); }
long long NCR(long long n, long long r) {
  if (r > n) return 0;
  long long ans =
      (fac[n] * ((Inv(fac[n - r])) % mod * (Inv(fac[r])) % mod) % mod) % mod;
  return ans % mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  string s;
  cin >> s;
  long long ans = n * (n - 1) / 2;
  vector<long long> v;
  long long i = 0;
  while (i < n) {
    long long j = i;
    while (j < n and s[j] == s[i]) j++;
    v.push_back(j - i);
    i = j;
  }
  for (int i = 0; i < v.size() - 1; i++) ans -= (v[i] + v[i + 1] - 1);
  cout << ans;
}
