#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long cnt = 0;
  vector<long long> aloc, bloc;
  for (long long i = 0; i < n; i++) {
    if (s[i] == 'A')
      aloc.push_back(i);
    else
      bloc.push_back(i);
  }
  aloc.push_back(n);
  bloc.push_back(n);
  long long asz = aloc.size(), bsz = bloc.size();
  for (long long i = 0; i < asz - 1; i++) {
    long long r = aloc[i + 1] - aloc[i] - 1;
    cnt += r;
    long long l;
    if (i == 0)
      l = aloc[i];
    else
      l = aloc[i] - aloc[i - 1] - 1;
    if (l > 1) cnt += (l - 1);
  }
  for (long long i = 0; i < bsz - 1; i++) {
    long long r = bloc[i + 1] - bloc[i] - 1;
    cnt += r;
    long long l;
    if (i == 0)
      l = bloc[i];
    else
      l = bloc[i] - bloc[i - 1] - 1;
    if (l > 1) cnt += (l - 1);
  }
  cout << n * (n - 1) / 2 - cnt << endl;
}
