#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  vector<long long> v;
  long long i = 0;
  while (i < n) {
    char tmp = s[i];
    long long cnt = 0;
    while (i + cnt < n and s[i + cnt] == tmp) {
      cnt++;
    }
    v.push_back(cnt);
    i += cnt;
  }
  long long m = v.size();
  if (m == 1) {
    long long ans = n * (n + 1) / 2 - n;
    cout << ans << endl;
    return 0;
  }
  long long diff = 0;
  for (long long i = 0; i < m; i++) {
    diff += 2 * v[i];
  }
  diff -= v[0];
  diff -= v[m - 1];
  diff -= m - 1;
  long long ans = n * (n + 1) / 2 - diff - n;
  cout << ans << endl;
  return 0;
}
