#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

  char s[4010];
  scanf("%s", s);

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) continue;
      for (int k = j + 1; k < n; k++) {
        if (j - i == k - j) continue;
        if (s[j] != s[k] && s[i] != s[k]) {
          ans++;
        }
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}
