#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,a,b) for(register int i = a;i <= b; ++i)
const int N = 4005;
ll n,a[N],r,g,b;
ll ans;
char ch[N];
int main() {
	scanf("%lld\n",&n);
	scanf("%s",ch+1);
	f(i,1,n) if(ch[i]=='R')++r,a[i]=3; else if(ch[i]=='G') ++g,a[i]=1; else ++b,a[i]=2;
	ans = r * g * b;
	f(i,1,n-2) {
		f(j,i+1,n-1) {
			if(2*j-i>n) break;
			if(a[j]!=a[i]) ans-=((a[i]^a[j])==a[2*j-i]);
		}
	}
	printf("%lld",ans);
}