#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r, g, b;
	r = g = b = 0;
	rep(i, s.size()){
		if(s[i] == 'R') r++;
		else if(s[i] == 'G') g++;
		else b++;
	}
	ll ans = (ll)r*g*b;
	cerr << ans << endl;
	rep(i, s.size()-1)rep2(j, i+1, s.size()){
		if(s[i] == s[j]) continue;
		int nx = i + (j-i)*2;
		if(nx >= s.size()) continue;
		if(s[i] != s[nx] && s[j] != s[nx]){
			// cerr << i << " " << j << " " << nx << endl;
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}