#include<stdio.h>
#include<string.h>
#define maxn 4010
int a[maxn],b[maxn],c[maxn];
int main ()
{   char s[maxn];
    int n; scanf("%d",&n);
    scanf("%s",s);
    long long  sum=0;
    for(int i=n-1;i>=0;i--)
    {   if(s[i]=='B') {a[i]=a[i+1];b[i]=b[i+1];c[i]=c[i+1]+1;}
        if(s[i]=='R') {a[i]=a[i+1]+1;b[i]=b[i+1];c[i]=c[i+1];}
        if(s[i]=='G') {a[i]=a[i+1];b[i]=b[i+1]+1;c[i]=c[i+1];}
	}
	for(int i=0;i<n;i++)
    {   if(s[i]=='R')
        {    for(int j=i+1;j<n;j++)
             {
			     if(s[j]=='G')
               {    sum+=c[j];
                    if(s[2*j-i]=='B') sum--;
			   }
			     if(s[j]=='B')
			      {   sum+=b[j];
                    if(s[2*j-i]=='G') sum--;
				  }
		      }
		}
		else if(s[i]=='G')
		{   for(int j=i+1;j<n;j++)
             {
			     if(s[j]=='R')
               {   sum+=c[j];
                    if(s[2*j-i]=='B') sum--;
			   }
			     if(s[j]=='B')
			      {   sum+=a[j];
                    if(s[2*j-i]=='R') sum--;
				  }
		      }
		}
		else if(s[i]=='B')
		{   for(int j=i+1;j<n;j++)
             {
			     if(s[j]=='G')
               {     sum+=a[j];
                    if(s[2*j-i]=='R') sum--;
			   }
			     if(s[j]=='R')
			      {  sum+=b[j];
                    if(s[2*j-i]=='G') sum--;
				  }
		      }
		}
	}
	 printf("%lld",sum);
}
