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



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