#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n = 0;
  string s;
  long long int res = 0ll;
  cin >> n;
  cin >> s;
  res = (1ll * n * (n + 1)) / 2ll - 1ll * n;
  for (int i = 0; i + 1 < n; ++i) {
    if (s[i] != s[i + 1]) {
      int j;
      for (j = i + 1; j < n; ++j) {
        if (s[i] == s[j]) break;
      }
      res -= (j - i - 1);
    }
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i + 1 < n; ++i) {
    if (s[i] != s[i + 1]) {
      int j;
      for (j = i + 1; j < n; ++j) {
        if (s[i] == s[j]) break;
      }
      res -= (j - i - 2);
    }
  }
  cout << res;
}
