#include <bits/stdc++.h>
using namespace std;
char s[300005];
int main() {
  long long n;
  cin >> n >> s;
  long long sub = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') continue;
    int j = i + 1;
    for (; j < n && s[j] != 'A'; j++) sub++;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') continue;
    int j = i + 1;
    for (; j < n && s[j] != 'B'; j++) sub++;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'A') continue;
    int j = i - 1;
    for (; j >= 0 && s[j] != 'B'; j--)
      if (j != i - 1) sub++;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'B') continue;
    int j = i - 1;
    for (; j >= 0 && s[j] != 'A'; j--)
      if (j != i - 1) sub++;
  }
  long long ans = n * (n - 1ll) / 2ll - sub;
  cout << ans;
}
