#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,j;
  long long int count,r=0,g=0,b=0;
  scanf("%d ",&n);
  char s[4010];
  for(i=0;i<=n;i++){
    scanf("%c",&s[i]);
    if(s[i]=='R')
      r++;
    else if(s[i]=='G')
      g++;
    else
      b++;
  }
  count=r*g*b;
  for(j=1;j<=n;j++){
    i=1;
    while(j+i*2<=n){
      if(s[j]!=s[j+i] && s[j+i]!=s[j+2*i] && s[j]!=s[j+2*i])
        count-=1;
      i+=1;
    }
  }
  printf("%lld\n",count);
  return 0;
}
