#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	int n;
	string s;
	cin >> n >> s;
	int r = 0, g = 0, b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R')
			r++;
		if (s[i] == 'G')
			g++;
		if (s[i] == 'B')
			b++;
	}
	long long ans = r * g * b;
	for (int i = 0; i < n - 2; i++) {
		for (int k = i + 2; k < n; k++) {
			if ((k + i) % 2 == 0 && s[i] != s[k] && s[i] != s[(k + i) / 2] && s[(k + i) / 2] != s[k])
				ans--;
		}
	}
	cout << ans << endl;
	return 0;
}