//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define mod 1000000007 //998244353
#define pb push_back
#define endd '\n'
#define ll long long 
#define mk make_pair 
#define fi first
#define all(a) a.begin(),a.end()
#define test ll int t,o;cin>>o;for(t=1;t<=o;t++)
#define goog(q,aao) cout<<"Case #"<<q<<": "<<aao<<'\n'
#define co(a) cout<<a<<'\n'
#define coo(a,b) cout<<a<<" "<<b<<'\n'
#define cooo(a,b,c) cout<<a<<" "<<b<<" "<<c<<'\n'
#define take_arr ll i,j,k,n;mul_itr;set_itr;cin>>n;ll arr[n];loop(i,n)cin>>arr[i]
#define take ll i,j,k,n;mul_itr;set_itr;cin>>n
#define print(arr,n) for(ll w=0;w<n;w++)cout<<arr[w]<<" ";cout<<'\n'
#define print_dou(arr,n,m) for(ll w=0;w<n;w++){ for(ll o=0;o<m;o++){cout<<arr[w][o]<<" "; }cout<<endd;}
#define dis(w) loop(i,w.size())cout<<w[i]<<" ";cout<<'\n'
#define mem(b,q)  memset(b,q , sizeof(b))
#define set_itr set<ll>:: iterator sitr ,sit
#define mul_itr multiset<ll>:: iterator itr,it
#define se second
#define pii pair<int,int>
#define iterate(s,d) for(d=s.begin();d!=s.end();++d)
#define pll pair<long long,long long>
#define vll vector<ll>
#define vpll vector< pair<ll,ll> >
#define vppll vector < pair<ll, pair<ll,ll> > >
#define trace(x) cout<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x,y,z) cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a,b,c,d) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define loop1(i,a,n) for(i=a;i<n; i++) 
#define loop(i,n) for( i=0;i<n;i++)
#define loop2(n,m) for(int p=0;p<n;p++)for(int q=0;q<m;q++)
#define loop3(n,m,l) for(int i=0;i<n;i++)for(int j=0;j<m;j++)for(int k=0;k<l;k++)
#define checkbit(n, b) ((n >> b) & 1)
#define setbits(x) __builtin_popcount(x)  // returns no of set bits in x 
#define maxx 10e18
using namespace std;
ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  	ll i,j,k,n, ans=0;
  	cin>>n;
  	ll dp[n][3];
  	mem(dp,0);
  	string s;
  	cin>>s;
  	vector<ll>r,b,g;
  	loop(i,s.length())
  	{
  		if(s[i]=='R')
  		{
  		
  			if(i>0)
  			{
  				dp[i][0]=dp[i-1][0]+1;
			  }
			else
			{
				dp[i][0]=1;
			}
			
			dp[i][1]=dp[i-1][1];
			dp[i][2]=dp[i-1][2];
		  }
		else if ( s[i]=='G')
		{
			g.pb(i);
			if(i>0)
  			{
  				dp[i][1]=dp[i-1][1]+1;
			  }
			else
			{
				dp[i][1]=1;
			}
			dp[i][2]=dp[i-1][2];
			dp[i][0]=dp[i-1][0];
		}
		else
		{
			b.pb(i);
			if(i>0)
  			{
  				dp[i][2]=dp[i-1][2]+1;
			  }
			else
			{
				dp[i][2]=1;
			}
			dp[i][0]=dp[i-1][0];
			dp[i][1]=dp[i-1][1];
		}
	  }
	 // print_dou(dp,n,3);
	 loop(i,n-2)
	 {
	 	for(j=i+1;j<n-1;j++)
	 	{
	 		if(s[i]=='R'&& s[j]=='B')
	 		{
	 			ans+= dp[n-1][1]-dp[j][1];
	 			if( 2*j-i <n && s[j+j-i]=='G')
	 			ans--;
			 }
			else if(s[i]=='R'&& s[j]=='G')
	 		{
	 			ans+= dp[n-1][2]-dp[j][2];
	 			if(2*j-i <n&& s[j+j-i]=='B')
	 			ans--;
			 }
			else if(s[i]=='B'&& s[j]=='R')
	 		{
	 			ans+= dp[n-1][1]-dp[j][1];
	 			if(2*j-i <n&&s[j+j-i]=='G')
	 			ans--;
			 }
			else if(s[i]=='B'&& s[j]=='G')
	 		{
	 			ans+= dp[n-1][0]-dp[j][0];
	 			if(2*j-i <n&& s[j+j-i]=='R')
	 			ans--;
			 }
			else if(s[i]=='G'&& s[j]=='B')
	 		{
	 			ans+= dp[n-1][0]-dp[j][0];
	 			if(2*j-i <n&& s[j+j-i]=='R')
	 			ans--;
			 }
		else if(s[i]=='G'&& s[j]=='R')
	 		{
	 			ans+= dp[n-1][2]-dp[j][2];
	 			if(2*j-i <n&& s[j+j-i]=='B')
	 			ans--;
			 }
		 }
	 }
	 cout<<ans;
	  
	
	  
	
    return 0;
}

Measured memory_bytes: 3712