#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
int N, x, y, z, count;
char S[4001];

  scanf("%d", &N);
  scanf("%s", S);
  count = 0;
  for (x = 0; x < N; ++x) {
    for (y = x + 1; y < N; ++y) {
      if (S[x] == S[y]) continue;
      for (z = y + 1; z < N; ++z) {
        if (y - x == z - y) continue;
        if (S[x] == S[z]) continue;
        if (S[y] == S[z]) continue;
        count++;
      }
    }
  }
  printf("%d\n", count);
    
  return 0;
}
