#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll ans,n,r,g,b;
string s;
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')r++;
		if(s[i]=='G')g++;
		if(s[i]=='B')b++;
	}
	ans=r*g*b;
	for(int i=0;i<n;i++)
	for(int j=i+1;j<n,2*j-i<n;j++)
	{
		if(s[i]!=s[j]&&s[j]!=s[2*j-i]&&s[i]!=s[2*j-1])
		ans--;
		
	}
	cout<<ans;
    return 0;
}