#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main()
{
	int n;
	string s;
	cin >> n >> s;
	
	ll cnt = 0;
	vector<ll> rgb(3);
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R')
			rgb[0]++;
		else if (s[i] == 'G')
			rgb[1]++;
		else
			rgb[2]++;
	}
	cnt = rgb[0] * rgb[1] * rgb[2];

	if (n > 2) {
		for (int d = 1; d < n; d++) {
			for (int i = 0; i < n; i++) {
				if (i + 2 * d >= n) {
					break;
				}
				else
				{
					if ((s[i] != s[i + d]) && (s[i + d] != s[i + 2 * d]) && (s[i + 2 * d] != s[i])) {
						cnt--;
					}
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}