#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

ll dp[4010][4];
ll a[4010][4010];
bool vis[4010];
map<char,int>mp;

char sol(char ch1,char ch2){
	if(ch1!='R'&&ch2!='R') return 'R';
	if(ch1!='G'&&ch2!='G') return 'G';
	 return 'B';
}

int main(){
	int n;
	char s[10010];
	mp['R']=1;
	mp['G']=2;
	mp['B']=3;
	cin>>n>>s+1;
	per(i,n,1){
	 rep(j,1,3)
		dp[i][j]=dp[i+1][j];
		dp[i][mp[s[i]]]+=1;
	}
	ll ans=0;
	rep(i,1,n-1){
		rep(j,i+1,n){
			if(s[i]==s[j]||j+1>n) continue;
			char ch=sol(s[i],s[j]);
			int cnt=dp[j+1][mp[ch]];
			if(j+j-i<=n&&s[j+j-i]==ch) cnt-=1;
			ans+=cnt;
	 }
 }
 cout<<ans<<'\n';
}

