#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
  if (y == 0)
    return 1;
  else if (y % 2 == 0)
    return power((x * x) % (long long int)1000000007, y / 2);
  else
    return (x * power((x * x) % (long long int)1000000007, (y - 1) / 2)) %
           (long long int)1000000007;
}
long long int modInverse(long long int n) {
  return power(n, (long long int)1000000007 - 2);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long int n;
    cin >> n;
    string s;
    cin >> s;
    long long int c = 1;
    vector<long long int> v;
    for (long long int i = 1; i < n; i++) {
      if (s[i] == s[i - 1])
        c++;
      else {
        v.push_back(c);
        c = 1;
      }
    }
    v.push_back(c);
    long long int ans = 0;
    for (long long int i = 0; i < v.size(); i++) ans += (v[i] * (v[i] - 1)) / 2;
    for (long long int i = 0; i < v.size() - 1; i++)
      ans += (v[i] - 1) * (v[i + 1] - 1);
    vector<long long int> v2(v.begin(), v.end());
    n = v.size();
    n -= 2;
    for (long long int i = n; i >= 0; i--) v2[i] += v2[i + 1];
    for (long long int i = 0; i < n; i++) {
      ans += v[i] * v2[i + 2];
    }
    cout << ans;
  }
}
