#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string str;
  cin >> str;
  int ans = 0;
  int cnt = 1;
  for (int i = 1; i < n; i++)
    if (str[i] != str[i - 1]) {
      ans += cnt;
      cnt = 1;
    } else
      cnt++;
  cnt = 1;
  for (int i = n - 2; i >= 0; i--)
    if (str[i] != str[i + 1]) {
      ans += cnt - 1;
      cnt = 1;
    } else
      cnt++;
  cout << n * (n - 1) / 2 - ans << endl;
}
int main() {
  solve();
  return 0;
}
