#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second 
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,a[3][4040];
string s;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>s;
	a[0][0]=a[1][0]=a[2][0]=0;
	fo(i,0,n+1){
		a[0][i+1]=a[0][i]+(s[i]=='R');
		a[1][i+1]=a[1][i]+(s[i]=='G');
		a[2][i+1]=a[2][i]+(s[i]=='B');
	}
	ll ans=0;
	fo(i,0,n-2) fo(j,i+1,n-1) if(s[i]!=s[j]){
		if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))ans+=a[2][n]-a[2][j+1]-(s[2*j-i]=='B');
		else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))ans+=a[1][n]-a[1][j+1]-(s[2*j-i]=='G');
		else ans+=a[0][n]-a[0][j+1]-(s[2*j-i]=='R');
	}
	cout<<ans<<endl;
	return 0;
}