#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 20;
vector<long long> seg;
int main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long tmp = 1;
  if (s[s.size() - 1] == 'A')
    s += 'B';
  else
    s += 'A';
  for (int i = 1; i < s.size(); i++) {
    if (s[i] != s[i - 1]) {
      seg.push_back(tmp);
      tmp = 1;
    } else
      tmp++;
  }
  int ans = 0;
  for (int i = 0; i < seg.size() - 1; i++) {
    ans += seg[i + 1] - 1;
  }
  for (int i = seg.size() - 1; i > 0; i--) {
    ans += seg[i - 1] - 1;
  }
  cout << (n * (n - 1) / 2) - ans - seg.size() + 1;
}
