#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 4010, M = 1010;

int n, cnt;
char s[N];

int check(int i, int j)
{
	if (s[i] == 'R' && s[j] == 'G' || s[i] == 'G' && s[j] == 'R')
	{
		int c = cnt, d = j - i;
		if (i - d >= 0 && s[i - d] == 'B') c -- ;
		if (j + d < n && s[j + d] == 'B') c -- ;

		d = (i + j) / 2;
		if (d - i == j - d && s[d] == 'B') c -- ;
		return c;
	}
	else return 0;
}

void solve()
{ 
	scanf("%d%s", &n, s);

	for (int i = 0; i < n; i ++ )
		if (s[i] == 'B')
			cnt ++ ;

	LL res = 0;
	for (int i = 0; i < n; i ++ )
		for (int j = i + 1; j < n; j ++ )
			res += check(i, j);

	printf("%lld\n", res);
}

int main()
{
	int T = 1;
	// scanf("%d", &T);
	// cin >> T;
	while (T -- ) solve();
	return 0;
}