// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
long long ng,r,g,b;

int main(){
	int N; string S; cin>>N>>S;
	for(int i=0; i<N; i++){
		if(S[i]=='R') r++; else if(S[i]=='G') g++; else b++;
		for(int j=i+1,k=i+2; k<N; k+=2,j++)
			if((S[i]^S[j]^S[k]) == ('R'^'G'^'B')) ng++;
	}
	cout<< r*g*b - ng <<endl;
}