#include <bits/stdc++.h>
using namespace std;

int main(){
	int n;
	string s;
	long long ans = 0;

	cin >> n >> s;

	vector<int> r, g, b;
	for(int i=0; i<n; i++){
		if(s[i] == 'R'){
			r.push_back(i);
		}else if(s[i] == 'G'){
			g.push_back(i);
		}else{
			b.push_back(i);
		}
	}

	sort(r.begin(), r.end());
	sort(g.begin(), g.end());
	sort(b.begin(), b.end());

	for(int i=0; i<r.size(); i++){
		for(int j=0; j<g.size(); j++){
			int cnt = 0,  d = abs(r[i] - g[j]);
			int sm = min(r[i], g[j]), bi = max(r[i], g[j]);

			if((r[i]+g[j]) % 2 == 0){
				cnt += count(b.begin(), b.end(), (r[i]+g[j])/2);
			}

			if(- d + sm >= 0){
				cnt += count(b.begin(), b.end(), -d+sm);
			}

			if(count(b.begin(), b.end(), d+bi)){
				cnt += count(b.begin(), b.end(), d+bi);
			}

			ans += b.size() - cnt;
		}
	}

	cout << ans << endl;
}

