#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 4e3 + 7;
int n;
char s[maxx];
int num[maxx];
vector <int> vec[maxx];
LL cnt[maxx];
bool vis[maxx];

LL chk(int a, int b, int c) {
	LL res = 0;
	for(int i = 0; i < vec[a].size(); i++) { //枚举首字母位置
		for(int j = 1; vec[a][i] + 2 * j <= n; j++) { //枚举间距
			if(num[vec[a][i] + j] == b && num[vec[a][i] + 2 * j] == c) res++;
		}
	}
	return res;
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'B') num[i] = 1;
		else if(s[i] == 'G') num[i] = 2;
		else if(s[i] == 'R') num[i] = 3;
	}
	for(int i = 1; i <= n; i++) {
		vec[num[i]].push_back(i);
		cnt[num[i]]++;
	}
	LL ans = cnt[1] * cnt[2] * cnt[3];
	ans -= chk(1, 2, 3) - chk(1, 3, 2) - chk(2, 1, 3);
	ans -= chk(2, 3, 1) - chk(3, 1, 2) - chk(3, 2, 1);
	printf("%lld\n", ans);
	return 0;
}