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

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

  scanf("%ld", &N);
  scanf("%s", S);
  count = 0;
  for (x = 0; x < N; ++x) {
    if (S[x] == 'R') {
      Sd[x] = 0.2;
    } else if (S[x] == 'G') {
      Sd[x] = 0.3;
    } else if (S[x] == 'B') {
      Sd[x] = 0.5;
    }
  }

  for (x = 0; x < N; ++x) {
    for (y = x + 1; y < N; ++y) {
      if (Sd[x] == Sd[y]) continue;
      diff = y - x;
      for (z = y + 1; z < N; ++z) {
        if (diff == z - y) continue;
        if (Sd[x] == Sd[z]) continue;
        if (Sd[y] == Sd[z]) continue;
        count++;
      }
    }
  }
  printf("%ld\n", count);
    
  return 0;
}
