#include <bits/stdc++.h>
using namespace std;
const int size = 1e6 + 1;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long int> a;
  int l = 0;
  while (l < n) {
    if (s[l] == 'A') {
      long long int c = 1;
      while (l + 1 < n and s[l + 1] == 'A') {
        c++;
        l++;
      }
      l++;
      a.push_back(c);
    } else if (s[l] == 'B') {
      long long int c = 1;
      while (l + 1 < n and s[l + 1] == 'B') {
        c++;
        l++;
      }
      l++;
      a.push_back(c);
    }
  }
  long long int ans = n * (n - 1);
  ans /= 2;
  long long int m = a.size();
  if (m == 1) {
    cout << ans;
    return 0;
  }
  ans -= (m - 1);
  for (int i = int(0); i < int(m); i++) {
    if (i == 0 or i == m - 1)
      ans -= 1ll * (a[i] - 1);
    else
      ans -= 2ll * (a[i] - 1);
  }
  cout << ans;
  return 0;
}
