#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> a, b;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'A')
      a.push_back(i);
    else
      b.push_back(i);
  }
  long long ans = 0;
  for (long long i = 0; i < n;) {
    long long ind = i;
    long long count = 0;
    while (i < n && s[i] == s[ind]) {
      i++;
      count++;
    }
    ans += count * (count - 1) / 2;
    if (i == n) break;
    if (count > 1) {
      if (n - i - 1 > 0) ans += (n - i - 1) * (count - 1);
    }
    if (s[i - 1] == 'A') {
      auto it = lower_bound(a.begin(), a.end(), i);
      if (it != a.end()) ans += (n - *it);
    } else {
      auto it = lower_bound(b.begin(), b.end(), i);
      if (it != b.end()) ans += (n - *it);
    }
  }
  cout << ans;
}
