#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int bad = n + n + n;
  for (int i = 0; s[i] == s[0] && i < n; i++, bad--)
    ;
  for (int i = 1; i < n; bad -= s[i - 1] != s[i], i++)
    ;
  for (int i = n - 1; s[i] == s[n - 1] && ~i; i--, bad--)
    ;
  cout << n * (n + 1LL) / 2 - bad;
}
