#include <stdio.h>

int main(void){
  char s[4001];
  int n,i,j,k;
  int ir=0,ig=0,ib=0;
  long int all;
  
  scanf("%d",&n);
  
  scanf("%s",s);
  
  for(i=0;i<n;i++){
    if(s[i]=='R')ir++;
    if(s[i]=='G')ig++;
    if(s[i]=='B')ib++;
  }
  
  all=ir*ig*ib;
  
  for(i=0;i<n;i++)for(j=i+1;j<n;j++){
    if(2*j-i<n)if(s[i]!=s[j] && s[i]!=s[2*j-i] && s[j]!=s[2*j-i])all--;
  }
  
  printf("%ld", all);
  
  return 0;
}

