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

int main() {
	int n;
	string s;
	cin >> n >> s;
	ll ans = 0;
	vector<ll> r(n), g(n), b(n);
	if(n <= 3) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, n) {
		if(s[i] == 'R') r[i]++;
		if(s[i] == 'G') g[i]++;
		if(s[i] == 'B') b[i]++;
		if(i > 0) {
			r[i] += r[i-1];
			g[i] += g[i-1];
			b[i] += b[i-1];
		}
	}
	// rep(i, n) cout << r[i] << " ";
	// cout << endl;
	// rep(i, n) cout << g[i] << " ";
	// cout << endl;
	// rep(i, n) cout << b[i] << " ";
	// cout << endl;
	rep(i, n-2) {
		for(int j = i+1; j < n-1; j++) {
			if(s[i] == s[j]) continue;
			char now = ((s[i] == 'R' || s[j] == 'R') && (s[i] == 'G' || s[j] == 'G')) ? 'B' : ((s[i] == 'R' || s[j] == 'R') && (s[i] == 'B' || s[j] == 'B')) ? 'G' : 'R';
			int dif = j - i;
			if(now == 'R') {
				ans += r[n-1] - r[min(n-1,j+dif)];
				if(dif>1) ans += r[min(n-1,j+dif-1)] - r[j];
			}
			if(now == 'G') {
				ans += g[n-1] - g[min(n-1,j+dif)];
				if(dif>1) ans += g[min(n-1,j+dif-1)] - g[j];
			}
			if(now == 'B') {
				ans += b[n-1] - b[min(n-1,j+dif)];
				if(dif>1) ans += b[min(n-1,j+dif-1)] - b[j];
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}