#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U>
ostream& operator<<(ostream& o, const pair<T, U>& p) {
  o << "(" << p.first << "," << p.second << ")";
  return o;
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> v;
  int start = 0;
  while (start < n) {
    int nx = start;
    while (nx < n && s[nx] == s[start]) ++nx;
    v.push_back(nx - start);
    start = nx;
  }
  int V = v.size();
  ll ans = 0;
  int idx = 0;
  for (int i = 0; i < (int)(V); ++i) {
    int x = v[i];
    int sub = 1;
    if (i == V - 1) sub = 0;
    for (int j = 0; j < (int)(x); ++j) {
      int add = n - 1 - idx - sub;
      if (j == x - 1) {
        if (i < V - 1) add -= v[i + 1] - 1;
      }
      ans += add;
      ++idx;
    }
  }
  cout << ans << "\n";
  return 0;
}
