#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;

int n;
char s[5010];
ll ans, sa, sb, sc;

int main(){

	scanf("%d %s", &n, s + 1);
	for(int i = 1; i <= n; i++){
		if(s[i] == 'R') sa++;
		if(s[i] == 'G') sb++;
		if(s[i] == 'B') sc++;
	}
	ans = sa * sb * sc;
	for(int i = 1; i <= n; i++)
		for(int j = 1; i - j >= 1 && i + j <= n; j++)
			if(s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j])
				ans--;
	printf("%lld\n", ans);

	return 0;
}
