#include <bits/stdc++.h>
using namespace std; 
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pb push_back
#define ull unsigned long long int
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define mo 1000000007
ll gcd(ll a ,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll poww(ll a,ll n){if(n==0)return 1;ll p=poww(a,n/2);p=(p*p)%mo;if(n%2)p=(a*p)%mo;return p;}
////////////////////////////////////////////////////
 int n ; string s;
 ll suf[4003][3]; 
 ll ans;
 void func(char a, char b , int x)
 { //if(a=='G'&&b=='R'&&x==2)
// cout<<ans<<"*"<<endl; 
 	for(int i = 1; i<n-1; i++)
 	{
 		if(s[i]!=b)
 		continue; 
 		for(int j = 0; j<i; j++)
 		{
 			if(s[j]!=a)
 			continue; 
 			int pos = i+(i-j); 
 			ans+=(suf[i+1][x]); 
 			if(pos<n&&s[pos]!=a&&s[pos]!=b)
 			ans--; 
		 }
	 }
	// if(a=='G'&&b=='R'&&x==2)
 //cout<<ans<<"*"<<endl; 
 }
ll tn ; 
void solve()
{
 cin>>n>>s; 
 ll a[3]={0}; 
 for(int i = n-1; i>=0 ; i--)
 {
 	if(s[i]=='R')
 	a[0]++; 
 	else if(s[i]=='G')
 	a[1]++; 
 	else
 	a[2]++; 
 	suf[i][0]=a[0];
 	suf[i][1]=a[1];
 	suf[i][2]=a[2];
 	
 }
 ans = 0; 
 string temp = "RGB"; 
 for(int i = 0; i<3; i++)
 {
 	for(int j = 0; j<3; j++)
 	{
 		for(int k = 0; k<3; k++)
 		{
 			if(i!=j&&i!=k&&j!=k)
 			{
 				func(temp[i],temp[j],k); 
 				//cout<<i<<" "<<j<<" "<<k<<" "<<ans<<endl; 
			 }
		 }
	 }
 }
 
 cout<<ans; 
}
int main()
{ ios; 

ll t ;t = 1; 
  for(tn = 1; tn<=t; tn++)
	solve(); 
	return 0 ; 
}