#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string str;
  cin >> str;
  int s[n];
  for (int i = 0; i < (n); ++i) {
    if (str[i] == 'A')
      s[i] = 0;
    else
      s[i] = 1;
  }
  int curr, j, sum = 0, check = 0;
  for (int i = 0; i < (n - 1); ++i) {
    if (s[i] != s[i + 1]) {
      curr = s[i + 1];
      j = i + 1;
      while (j < n && s[j] == curr) j++;
      sum += (j - i - 1);
      i = j - 2;
    }
  }
  for (int i = 0; i < (n - 1); ++i) {
    if (s[i] == s[i + 1]) {
      curr = s[i];
      j = i;
      while (j < n && s[j] == curr) j++;
      if (j < n && s[j] != curr) {
        sum += (j - i);
        check++;
      }
      i = j - 1;
    }
  }
  long long tot = (n * (n - 1));
  long long tot2 = tot / 2;
  cout << tot2 - sum + check;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
