#include  <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int n,i,j,k,r=0, g=0 ,b=0;
  long long count=0;
  char s[4005];
  scanf("%d",&n);
  scanf("%s",s);
  n=strlen(s);
  for(int l=0;l<n;l++){
    if(s[l]=='R') r++;
    if(s[l]=='G') g++;
    if(s[l]=='B') b++;
  }
  count=r*g*b;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      k=2*j-i;
      if(k<n){
      if(s[i]=='R'&&s[j]=='G'&&s[k]=='B') count--;
      if(s[i]=='R'&&s[j]=='B'&&s[k]=='G') count--;
      if(s[i]=='G'&&s[j]=='R'&&s[k]=='B') count--;
      if(s[i]=='G'&&s[j]=='B'&&s[k]=='R') count--;
      if(s[i]=='B'&&s[j]=='R'&&s[k]=='G') count--;
      if(s[i]=='B'&&s[j]=='G'&&s[k]=='R') count--;
      }
    }
  }
  printf("%lld",count);

  return 0;
}



