#include<stdio.h>

int main(void){
  unsigned int i,j,k;
  unsigned int r = 0,g = 0,b = 0;
  unsigned int len;
  unsigned long cnt = 0;

  scanf("%d",&len);
  char str[len];
  scanf("%s",str);

  for(i = 0;i < len;i++){
    if(str[i] == 'R'){
      r++;
    }
    else if(str[i] == 'G'){
      g++;
    }
    else if(str[i] == 'B'){
      b++;
    }
  }
  cnt = r * g * b;

  for(i = 0;i < len;i++){
    for(j = i+1;j < len;j++){
      if((j+j-i) < len){
        if((str[i] != str[j]) && (str[j] != str[j+j-i]) && (str[j+j-i] != str[i])){
          cnt--;
        }
      }
    }
  }
  printf("%ld",cnt);
  return 0;
}
