#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 10;
const int M = 1000 * 1000 * 1000 + 7;
const long long INFLL = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> b(n, n);
  for (int i = n - 2; i >= 0; --i) {
    if (s[i] == s[i + 1])
      b[i] = b[i + 1];
    else
      b[i] = i + 1;
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) {
      ans += b[i] - i - 1;
      ans += max(0, n - b[i] - 1);
    } else if (s[i] != s[i + 1] && s[i] == s[i + 2]) {
      ans += n - (i + 2);
    } else {
      ans += n - b[i + 1];
    }
  }
  cout << ans;
}
