#include <bits/stdc++.h>
#include <set>
using namespace std;

int main() {
	long long n;
	string s;
	cin >> n;
	cin >> s;
	long long r, g, b;
	for (long long i = 0; i < n; ++i)
	{
		if (s[i] == 'R') r++;
		if (s[i] == 'G') g++;
		if (s[i] == 'B') b++;
	}
	long long dec = 0;
	for (long long i = 1; i < n/2; ++i) // 間隔
	{
		for (long long j = 0; j < n - 2 * i; ++j) // 開始位置
		{
			if (s[j] != s[j + i] && s[j] != s[j + 2 * i] && s[j + i] != s[j + 2 * i]) dec++;
		}
	}
	if (n%2 == 1)
	{
		if(s[1] == s[1 + n/2] && s[1] == s[n-1] && s[1 + n/2] == s[n-1]) dec++;
	}
	cout << r * g * b - dec << endl;
}