#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long int

int main(){
  ll n;
  scanf("%lld",&n);
  char s[4001];
  scanf("%s",s);

  ll ans=0;
  ll dec=0;

  for(int inte=1;inte<=n/2;inte++){
    for(int fir=0;fir+2*inte<n;fir++){
      int sec=fir+inte;
      int thi=sec+inte;
	if(s[fir]==s[sec] || s[sec]==s[thi] || s[thi]==s[fir]){
	  continue;}
	//printf("%d %d %d\n",i,j,k);
	dec++;
      }}
  ll r=0;
  ll b=0;
  ll g=0;
  for(int i=0;i<n;i++){
    if(s[i]=='R') r++;
    else if(s[i]=='B') b++;
    else if(s[i]=='G') g++;
  }
  ans = r*b*g-dec;

  printf("%lld\n",ans);
  
  return 0;
}
