#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
	int n;
  	cin >>n;
  	string s;
  	cin >>s;
  long int cr=0,cg=0,cb=0,ans=0,count=0;
  
  rep(i,n){
   if(s[i]=='R'){cr++;}
   if(s[i]=='B'){cb++;}
	if(s[i]=='G'){cg++;}
  }
 
  for(long int d;d<=n/2;d++){
  	for(long int i=0;i+2*d<n;i++){
    long int j=i+d,k=i+2*d;
    if(s[i]!=s[j]&&s[k]!=s[j]&&s[i]!=s[k])
    	{count++;}
    }
  } 
  cout<<cb*cr*cg-count<<endl;
}