#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

string t = "RGB";

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<vector<int>> v(3, vector<int>(n,0));
	vector<map<int,int>> mp(3);
	rep(i,n){
		if(s[i] == 'R') {
			v[0][i]++;
			mp[0][i]++;
		}
		if(s[i] == 'G'){
			v[1][i]++;
			mp[1][i]++;
		}
		if(s[i] == 'B'){
			v[2][i]++;
			mp[2][i]++;
		}
	}
	rep(i,3){
		rep(j,n){
			if(j>0) v[i][j] += v[i][j-1];
		}
	}
	
	int ans = 0;
	
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			if(s[i] == s[j]) continue;
			int id;
			rep(k,3){
				if(t[k] != s[i] && t[k] != s[j]) id = k;
			}
			ans += v[id][n-1] - v[id][j];
			if(2*j-i<n && mp[id][2*j-i] != 0) ans--;
		}
	}
	cout << ans << endl;
    return 0;
}

