#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;

long long const inf = 2e18, linf = 2e9, mod = 1e9+7;
int const mxn = 1e6 + 10 ;  ; 

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

long long ans , ans2 ; 
int R[mxn] , G[mxn] , B[mxn]  ; 
string  s; 
int main(){
	int n ; 
	cin>> n ; 
	cin>>s ; 
	s = "." + s ; 
	for (int i = 1; i <= n ; i++){
		R[i] = R[i-1] + (s[i]=='R') ; 
		G[i] = G[i-1] + (s[i]=='G') ; 
		B[i] = B[i-1] + (s[i]=='B') ; 
	}
	
	
	
	for (int i = 1 ; i <= n ; i++){
		if (s[i]=='R'){
			ans+=G[i] * (B[n] - B[i]) ; 
			ans+=B[i] * (G[n] - G[i]) ; 
		}
		if (s[i]=='G'){
			ans+=R[i] * (B[n] - B[i]) ; 
			ans+=B[i] * (R[n] - R[i]) ; 
		}
		if (s[i]=='B'){
			ans+=R[i] * (G[n] - G[i]) ; 
			ans+=G[i] * (R[n] - R[i]) ;
		}
	}
	for (int i = 1 ; i <=n ; i++){
		for (int j = i+1 ; j <=n ; j++){
			if ((j - i)%2==0){
				int b = (j+i) / 2; 
				if (s[i]!=s[j] and s[b]!=s[j] and s[b]!=s[i])
					ans2++ ;
			}
		}
	}
	//cout<<ans<<endl;
	cout<<ans - ans2  ; 

}