// Problem : D - RGB Triplets
// Contest : AtCoder - AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=4000+10;
char s[maxn];

int id(char ch){
	if(ch=='R') return 1;
	if(ch=='G') return 2;
	return 3;
}

int sum[maxn][4];

int main()
{
	int n;
	cin>>n;
	scanf("%s",s+1);
	rep(i,1,n){
		rep(j,1,3) sum[i][j]=sum[i-1][j];
		++sum[i][id(s[i])];
	}

	ll ans=0;	
	rep(i,1,n){
		rep(j,i+2,n) if(s[i]!=s[j]){
			int v=1;
			for(;v<=3;++v){
				if(v!=id(s[i]) && v!=id(s[j])) break;
			}
			ans+=sum[j][v]-sum[i-1][v];
			if(((i+j)&1) == 0 && id(s[(i+j)/2]) == v) --ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}
