#include <bits/stdc++.h>

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int cnt[MAX];
char _s[MAX];
int s[MAX];
ll sol;
int n;

void solve(int poc){
	REP(i,300) cnt[i]=0;
	FOR(i,poc+1,n) cnt[s[i]]++;
	FOR(nx,poc+1,n){
		cnt[s[nx]]--;
		if (s[nx]==s[poc]) continue;
		sol+=cnt['R']+cnt['G']+cnt['B'];
		sol-=cnt[s[poc]];
		sol-=cnt[s[nx]];
		int d=nx + (nx-poc);
		if (d>=n) continue;
		if (s[d]!=s[poc] && s[d]!=s[nx]) sol--;
	}
}

int main(){
	scanf ("%*d");
	scanf ("%s",_s);
	n=strlen(_s);
	REP(i,n) s[i]=(int)_s[i];
	REP(i,n) solve(i);
	
	printf ("%lld\n",sol);
	return 0;
}
