/* author   : mpily :-()
title : Competing.cpp
time :Fri Apr 10 17:19:34 2020

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int dp[4002][3];//dp[i][0] = number of R.. [i][1] number of B...[i][2] number of G
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	map<char,int>nums;
	nums['R'] = 0;
	nums['B'] = 1;
	nums['G'] = 2;
	cin >> n >> s;
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	for(int i = 0; i < n; ++i){
		if(i){
			dp[i][0] = dp[i-1][0];
			dp[i][1] = dp[i-1][1];
			dp[i][2] = dp[i-1][2];
		}
		dp[i][nums[s[i]]]+=1;
	}
	long long ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = i+1; j < n; ++j){
			if(s[i] == s[j])continue;
			int tot = 'R'+'G'+'B';
			tot-=s[i];
			tot-=s[j];
			char a = tot;
			ans+=(dp[n-1][nums[a]] - dp[j][nums[a]]);
			if(s[j+j-i] == a)ans-=1;
		//	cout<<"at position "<<i<<" "<<s[i]<<" "<<s[j]<<" :: "<<a<<" "<<dp[n-1][nums[a]] - dp[j][nums[a]]<<"\n";
		}
	}
	cout<<ans<<"\n";
	return 0;
}
