#include <bits/stdc++.h>
using namespace std;
int n;
char str[300005];
int main() {
  cin >> n >> str + 1;
  long long ans = 0;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (i == 1 || str[i] == str[i - 1]) {
      cnt++;
      ans = ans + i - 1 - (cnt < i);
    } else {
      ans = ans + i - 1 - cnt;
      cnt = 1;
    }
  }
  cout << ans << endl;
}
