#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 10;
int mark[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> v;
  int rn = 1;
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) {
      v.push_back(rn);
      rn = 0;
    }
    rn++;
  }
  v.push_back(rn);
  for (int i = 0; i < v.size(); i++) {
    if (i != 0) ans += v[i - 1];
    if (i != ((int)v.size() - 1)) ans += v[i + 1] - 1;
  }
  long long rtr = (long long)n * (n - 1) / 2 + n - ans - n;
  cout << rtr;
}
