#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,r,g,b;
ll ans;
string s;
int main()
{
   cin>>n>>s;
   for(int i=0;i<n;i++)
   {
   	  if(s[i]=='R')r++;  
	  if(s[i]=='G')g++;  
	  if(s[i]=='B')b++;
	} 
   ans=r*g*b;
   for(int i=0;i<n;i++)
     for(int j=i+1;j<n,2*j-i<n;j++)
     {
     	if(s[i]!=s[j]&&s[j]!=s[2*j-i]&&s[i]!=s[2*j-i]) ans--;
	 }
   cout<<ans;
return 0;
}
