#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  string a;
  cin >> n;
  cin >> a;
  long long s = n * (n - 1) / 2;
  long long ans = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 'A') {
      for (int j = i + 1; j < n; j++) {
        if (a[j] == 'B')
          ans++;
        else
          break;
      }
      for (int j = i - 1; j >= 0; j--) {
        if (a[j] == 'B')
          ans++;
        else
          break;
      }
    } else if (a[i] == 'B') {
      for (int j = i + 1; j < n; j++) {
        if (a[j] == 'A')
          ans++;
        else
          break;
      }
      for (int j = i - 1; j >= 0; j--) {
        if (a[j] == 'A')
          ans++;
        else
          break;
      }
    }
  }
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) sum++;
  }
  ans = ans - sum;
  cout << s - ans;
  return 0;
}
