#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>



int main() {
  unsigned long long a, b, c, r, tmp, i, j = 0, k, num = 0,  ans = 0, N = 0;
  char S[4010];
  scanf("%d %s", &N, S);
  for (i = 0; i < N - 2; i++) {
    for (j = i + 1; j < N - 1; j++) {
      if (S[i] != S[j]) {
        for (k = j + 1; k < N; k++) {
          if (S[i] != S[k] && S[j] != S[k] && j - i != k - j) ans++;
        }
      }
    }
  }
  printf("%llu", ans);
  return 0;
}
