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

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> resr(n + 1), resg(n + 1), resb(n + 1);
	rep(i, n) {
		if (s[i] == 'R') resr[i]++;
		if (s[i] == 'G') resg[i]++;
		if (s[i] == 'B') resb[i]++;
		resr[i + 1] += resr[i];
		resg[i + 1] += resg[i];
		resb[i + 1] += resb[i];
	}
	int ans = 0;
	rep(i, n - 2) {
		for (int j = i + 1; j < n - 1; ++j) {
			if (s[i] == 'R' && s[j] == 'G') {
				ans += resb[n] - resb[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'B') ans--;
			}
			if (s[i] == 'R' && s[j] == 'B') {
				ans += resg[n] - resg[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'G') ans--;
			}
			if (s[i] == 'G' && s[j] == 'R') {
				ans += resb[n] - resb[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'B') ans--;
			}
			if (s[i] == 'B' && s[j] == 'R') {
				ans += resg[n] - resg[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'G') ans--;
			}
			if (s[i] == 'B' && s[j] == 'G') {
				ans += resr[n] - resr[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'R') ans--;
			}
			if (s[i] == 'G' && s[j] == 'B') {
				ans += resr[n] - resr[j];
				int tmp = j + (j - i);
				if (j + (j - i) > n) continue;
				if (s[tmp] == 'R') ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}