#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,p[maxn],x[maxn][10],ans;
char s[maxn];

int main()
{
	n=read(); scanf("%s",s+1);
	for(int i=n;i>=1;i--)
	{
		rep(j,1,3) x[i][j]=x[i+1][j];
		if(s[i]=='R') p[i]=1,x[i][1]++;
		if(s[i]=='G') p[i]=2,x[i][2]++;
		if(s[i]=='B') p[i]=3,x[i][3]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			//cout<<i<<" "<<j<<endl;
			if(s[i]==s[j]) continue;
			int t=j+(j-i),q=6-p[i]-p[j];
			if(p[t]==q) ans+=x[j+1][q]-1;
			else ans+=x[j+1][q];
		}
	}
	cout<<ans<<endl;
	return 0;
}