#include <bits/stdc++.h>
#define ll long long
#define oo 1000000010
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n, ans = 0;
	cin >> n;
	string s;
	cin >> s;
	for(int i=0; i<n; i++){
		int l = i + 1, r = i + 2, cntR = 0, cntG = 0, cntB = 0;
		for(int j=i+1; j<n; j++){
			if(s[j] == 'R') cntR++;
			if(s[j] == 'G') cntG++;
			if(s[j] == 'B') cntB++;
		}
		if(s[i] == 'R'){
			ans += cntG*cntB;
			while(r < n){
				if(s[i] != s[r] && s[i] != s[l] && s[r] != s[l]) ans--;
				l++, r+=2;
			}
		}
		else if(s[i] == 'G'){
			ans += cntR*cntB;
			while(r < n){
				if(s[i] != s[r] && s[i] != s[l] && s[r] != s[l]) ans--;
				l++, r+=2;
			}
		}
		else if(s[i] == 'B'){
			ans += cntG*cntR;
			while(r < n){
				if(s[i] != s[r] && s[i] != s[l] && s[r] != s[l]) ans--;
				l++, r+=2;
			}
		}
	}
	cout << ans;

	return 0;
}
