#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define MOD 1000000000000000000
#define inf -100000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//number of edges in a graph equal (v[i].size() ka summation of all the vertices)/2
int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll int n;
    cin>>n;
   	string s;
   	cin>>s;
   	ll int leftg=0,leftb=0,rightb=0,rightg=0,j,i;
   	ll int val;
   	ll int ans=0;
   	ll int green[n]={0},blue[n]={0},red[n]={0};
   	for(i=0;i<n;i++)
   	{
   		if(s[i]=='G')
   			green[i]++;
   		if(s[i]=='B')
   			blue[i]++;
   		if(s[i]=='R')
   			red[i]++;
   	}
   	for(i=n-2;i>=0;i--)
   	{
   		green[i]+=green[i+1];
   		blue[i]+=blue[i+1];
   		red[i]+=red[i+1];
   	}
   	for(i=0;i<n;i++)
   	{
   		if(s[i]=='R')
   		{ll int a[4005]={0},b[4003]={0},c[4005]={0},d[4005]={0};
   		leftg=0,leftb=0,rightb=0,rightg=0;
   			for(j=i-1;j>=0;j--)
   			{
   				if(s[j]=='G')
   				{
   					a[i-j]=-1;
   					leftg++;
   				}
   				if(s[j]=='B')
   				{
   					b[i-j]=-1;
   					leftb++;
   				}

   			}
   			for(j=i+1;j<n;j++)
   			{
   				if(s[j]=='G')
   				{
   					c[i-j]=-1;
   					rightg++;
   				}
   				if(s[j]=='B')
   				{
   					d[i-j]=-1;
   					rightb++;
   				}

   			}

   			val=leftg*rightb+leftb*rightg;
   			ll int count1=0,count2=0;
   			for(j=0;j<4000;j++)
   			{
   				if(a[j]==-1 && d[j]==-1)
   					count1++;
   				if(b[j]==-1 && c[j]==-1)
   					count2++;
   			}
   			val=val-count1-count2;
   			//ans=ans+val;
   			val=0;ll int z;
   			for(j=i+1;j<n;j++)
   			{
   				if(s[j]=='G')
   				{
   					z=j-i;
   					if((j+z)<n && s[j+z]=='B')
   						val=val+blue[j]-1;
   					else
   						val=val+blue[j];
   				}
   				else if(s[j]=='B')
   				{
   					z=j-i;
   					if((j+z)<n && s[j+z]=='G')
   						val=val+green[j]-1;
   					else
   						val=val+green[j];
   				}
   			}
   			ans=ans+val;

   		}
   		else if(s[i]=='G')
   		{ll int a[4005]={0},b[4003]={0},c[4005]={0},d[4005]={0};
   			leftg=0,leftb=0,rightb=0,rightg=0;
   			for(j=i-1;j>=0;j--)
   			{
   				if(s[j]=='R')
   				{
   					a[i-j]=-1;
   					leftg++;
   				}
   				if(s[j]=='B')
   				{
   					b[i-j]=-1;
   					leftb++;
   				}

   			}
   			for(j=i+1;j<n;j++)
   			{
   				if(s[j]=='R')
   				{
   					c[i-j]=-1;
   					rightg++;
   				}
   				if(s[j]=='B')
   				{
   					d[i-j]=-1;
   					rightb++;
   				}

   			}ll int count1=0,count2=0;
   			val=leftg*rightb+leftb*rightg;
   			for(j=0;j<4000;j++)
   			{
   				if(a[j]==-1 && d[j]==-1)
   					count1++;
   				if(b[j]==-1 && c[j]==-1)
   					count2++;
   			}
   			val=val-count1-count2;
   			//ans=ans+val;
   			val=0;ll int z;
   			for(j=i+1;j<n;j++)
   			{
   				if(s[j]=='R')
   				{
   					z=j-i;
   					if((j+z)<n && s[j+z]=='B')
   						val=val+blue[j]-1;
   					else
   						val=val+blue[j];
   				}
   				else if(s[j]=='B')
   				{
   					z=j-i;
   					if((j+z)<n && s[j+z]=='R')
   						val=val+red[j]-1;
   					else
   						val=val+red[j];
   				}
   			}
   			ans=ans+val;
   		}
   		else if(s[i]=='B')
   		{ll int a[4005]={0},b[4003]={0},c[4005]={0},d[4005]={0};
   			leftg=0,leftb=0,rightb=0,rightg=0;
   			for(j=i-1;j>=0;j--)
   			{
   				if(s[j]=='G')
   				{
   					a[i-j]=-1;
   					leftg++;
   				}
   				if(s[j]=='R')
   				{
   					b[i-j]=-1;
   					leftb++;
   				}

   			}
   			for(j=i+1;j<n;j++)
   			{
   				if(s[j]=='G')
   				{
   					c[i-j]=-1;
   					rightg++;
   				}
   				if(s[j]=='R')
   				{
   					d[i-j]=-1;
   					rightb++;
   				}

   			}ll int count1=0,count2=0;
   			val=leftg*rightb+leftb*rightg;
   			for(j=0;j<4000;j++)
   			{
   				if(a[j]==-1 && d[j]==-1)
   					count1++;
   				if(b[j]==-1 && c[j]==-1)
   					count2++;
   			}
   			val=val-count1-count2;
   			//ans=ans+val;
   			val=0;ll int z;
   			for(j=i+1;j<n;j++)
   			{
   				if(s[j]=='G')
   				{
   					z=j-i;
   					if((j+z)<n && s[j+z]=='R')
   						val=val+red[j]-1;
   					else
   						val=val+red[j];
   				}
   				else if(s[j]=='R')
   				{
   					z=j-i;
   					if((j+z)<n && s[j+z]=='G')
   						val=val+green[j]-1;
   					else
   						val=val+green[j];
   				}
   			}
   			ans=ans+val;
   		}
   		

   	}
   	cout<<ans<<endl;
   }

Measured memory_bytes: 3724