// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
long long ng,r,g,b;

int main(){
	int N; string S; cin>>N>>S;
	rep(i, N){
		S[i]=='R'? r++: S[i]=='G'? g++: b++;
		rep(d, N/2){
			int j = i + d, k = j + d;
			if(k >= N) break;
			if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ng++;
		}
	}
	cout<< r*g*b - ng <<endl;
}