#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#ifndef LOCAL
#define endl '\n'
#endif

const int mod = 1e9 + 7;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

const int N = 4005;
int pre[3][N];
string ss = "RGB";

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			pre[j][i] = pre[j][i - 1] + (s[i - 1] == ss[j]);
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(s[i] == s[j]) continue;
			char ch = s[i] ^ s[j] ^ 'R' ^ 'B' ^ 'G';
			int k;
			for(int l = 0; l < 3; l++) {
				if(ss[l] == ch) k = l;
			}
			ans += pre[k][n] - pre[k][j];
			int kk = i + (j - i) * 2;
			if(kk < n && s[kk] == ch) {
				ans--;
			}
		}
	}
	cout << ans;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}