#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {

	int n;
	string s; 
	cin >> n >> s;
	/*vector<vector<int> > hoge(6, vector<int>());
	//rgb,rbg,grb,gbr,brg,bgr
	vector<int> rafterg;
	vector<int> bafterg;
	int countr = 0, countb=0, countg = 0;
	rep(i,n) {
		if(s[i] == 'B') {
			countb++;
			hoge[1].pb(countr);
			hoge[3].pb(countg);
		}
		if(s[i] == 'R') {
			hoge[2].pb(countg);
			hoge[4].pb(countb);
			countr++;
		}
		if(s[i] == 'G') {
			countg++;
			hoge[0].pb(countr);
			hoge[5].pb(countb);
		}
			
	}
	countr = 0;
	countb=0;
	countg = 0;
	//rgb,rbg,grb,gbr,brg,bgr
	vector<vector<int> > fuga(6, vector<int>());
	for(int i=n-1; i>=0; i--) {
		if(s[i] == 'R') {
			countr++;
			fuga[2].pb(countb);
			fuga[4].pb(countg);
		}
		if(s[i] == 'G') {
			countg++;
			fuga[0].pb(countb);
			fuga[5].pb(countr);
		}
		if(s[i] == 'B') {
			countb++;
			fuga[1].pb(countg);
			fuga[3].pb(countr);
		}
		if(s[i] == 'G') bafterg.pb(countb);
	}
	rep(i,6) {
		reverse(fuga[i].begin(), fuga[i].end());
	}
	ll ans = 0;
	rep(i,6) {
		rep(j, fuga[i].size()) {
			ans += fuga[i][j] * hoge[i][j];
		}
	}
	/*rep(i, rbeforeg.size()) {
		ans += rbeforeg[i] * bafterg[i];
		cout << rbeforeg[i] << " " << bafterg[i] << endl;
	}*/
	
	//reverse(bafterg.begin(), bafterg.end());
	ll ans = 1;
	ll countr = 0, countg = 0, countb = 0;
	rep(i,n) {
		if(s[i] == 'R') countr++;
		if(s[i] == 'G') countg++;
		if(s[i] == 'B') countb++;
	}
	ans *= countr;
	ans *= countb;
	ans *= countg;
	for(int i=1;i <= (n-1)/2; i++) {
		rep(j,n) {
			if(j + 2*i >= n) continue;
			if(s[j] == 'R' && s[j+i] == 'G' && s[j+2*i] == 'B') ans--;
			if(s[j] == 'R' && s[j+i] == 'B' && s[j+2*i] == 'G') ans--;
			if(s[j] == 'B' && s[j+i] == 'R' && s[j+2*i] == 'G') ans--;
			if(s[j] == 'B' && s[j+i] == 'G' && s[j+2*i] == 'R') ans--;
			if(s[j] == 'G' && s[j+i] == 'B' && s[j+2*i] == 'R') ans--;
			if(s[j] == 'G' && s[j+i] == 'R' && s[j+2*i] == 'B') ans--;
		}
	}

	cout << ans << endl;
  return 0;
}
