#include<iostream>

using namespace std;

int main() {
	int n;
	string s;
	int r=0, g=0, b=0;
	long long count;

	cin >> n >> s;
	for (int i = 0;i < n;i++) {
		switch (s[i])
		{
		case 'R':
			r++;
			break;
		case 'G':
			g++;
			break;
		case 'B':
			b++;
			break;
		default:
			break;
		}
	}
	count = r * g * b;
	for (int i = 0;i < n;i++) {
		for (int j = i + 1;2*j < (n+i);j++) {
			if (s[i] != s[j] && s[j] != s[2 * j - i] && s[i] != s[2 * j - i])count--;
		}
	}

	cout << count << "\n";
	return 0;

}