#include <bits/stdc++.h>
using namespace std;
long long int power_mod(long long int a, long long int x) {
  if (x == 0) return 1;
  long long int y = power_mod(a, x / 2);
  long long int ans = (y * y) % 1000000007;
  if (x % 2) ans = (ans * a) % 1000000007;
  return ans;
}
long long int inv(long long int a) { return power_mod(a, 1000000007 - 2); }
long long int power(long long int a, long long int x) {
  if (x == 0) return 1;
  long long int y = power(a, x / 2);
  long long int ans = (y * y);
  if (x % 2) ans *= a;
  return ans;
}
int main() {
  string s;
  long long int n;
  cin >> n >> s;
  long long int ct1 = 0, ct2 = 0;
  long long int buffer = 0;
  for (int i = 0; i < n;) {
    char x = s[i];
    ct1 = 0;
    while (s[i] == x) {
      i++;
      ct1++;
      if (i == n) break;
    }
    if (ct2 != 0) buffer += (ct2 + ct1 - 1);
    if (i == n) break;
    x = s[i];
    ct2 = 0;
    while (s[i] == x) {
      i++;
      ct2++;
      if (i == n) break;
    }
    buffer = buffer + ct2 + ct1 - 1;
  }
  long long int ans = (n * (n - 1)) / 2;
  cout << ans - buffer << endl;
}
