
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define sz(a)       (ll)(a.size())
#define cr(P)       cout<<P<<"\n";return;
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,x,n)   for(ll i=x;i<n;i++)
#define frr(i,x,n)  for(ll i=n-1;i>=x;i--)
using namespace std;


const ll N   =  500005;
const ll mod = 1e9 + 7;

ll f(vector<ll> a,vector<ll> b,vector<ll> c){
	ll ans =0,x;
	for(auto i : a){
		for(auto j : b){
			if(j> i){
				//cout << i << " "<<j <<" "<< 2 * j - i<<"\n";
				x = c.size() - (upper_bound(c.begin(), c.end(),j) -c.begin());
			if(x>0 and binary_search(c.begin(), c.end(),2*j-i)){
				ans +=x-1;
			}
			else ans+=x;
			}
		}
	}
	return ans;
}

void solve(){
vector<ll>v[3];

  ll x=0,y=0,c=0,ans=0;
  ll n,m,k;
  cin>>n;
 	string s;
 	cin>>s;
 	for (ll i = 0; i < n; ++i){
 			
 		if(s[i]=='R')
 			v[0].pb(i+1);
 		else if(s[i]=='G')
 			v[1].pb(i+1);
 		else v[2].pb(i+1);
 	}

 	ans+=f(v[1],v[2],v[0]) + f(v[1],v[0],v[2]) + f(v[0],v[2],v[1])+ f(v[0],v[1],v[2])
 	 + f(v[2],v[1],v[0]) + f(v[2],v[0],v[1]) ;
 	c(ans);
}

signed main(){
     
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  //int T;cin >> T;while (T--)
  solve();
  return 0;
}
