#include<iostream>
using namespace std;
#define int long long int
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    string str;
    cin>>str;
    int suffix1[n+1]={0};
    int suffix2[n+1]={0};
    int suffix3[n+1]={0};
    int i,j;
    for(j=0;j<n;j++)
    {
		if(str[j]=='R')
		{
			suffix1[j]++;
		}
		else if(str[j]=='G')
	    {
			suffix2[j]++;
		}
		else 
		{
			suffix3[j]++;
		}
	}	
	for(j=n-1;j>=0;j--)
	{
		suffix1[j]+=suffix1[j+1];
		suffix2[j]+=suffix2[j+1];
		suffix3[j]+=suffix3[j+1];
	}
	int answer=0;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if((str[i]=='R'&&str[j]=='G')||(str[i]=='G'&&str[j]=='R'))
			{
				answer=answer+suffix3[j];
				int diff=j-i;
				int k=j+diff;
				if(k<n&&str[k]=='B')
				{
					answer--;
				}
			}
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if((str[i]=='R'&&str[j]=='B')||(str[i]=='B'&&str[j]=='R'))
			{
				answer=answer+suffix2[j];
				int diff=j-i;
				int k=j+diff;
				if(k<n&&str[k]=='G')
				{
					answer--;
				}
			}
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if((str[i]=='B'&&str[j]=='G')||(str[i]=='G'&&str[j]=='B'))
			{
				answer=answer+suffix1[j];
				int diff=j-i;
				int k=j+diff;
				if(k<n&&str[k]=='R')
				{
					answer--;
				}
			}
		}
	}
	cout<<answer<<endl;
}
