#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
string S;
ll ans;
ll r = 0;
ll g = 0;
ll b = 0;

int main(){
	
	cin>>N>>S;
	REP( i, N ){
		if( S[i] == 'R' ) r++;
		if( S[i] == 'G' ) g++;
		if( S[i] == 'B' ) b++;
	}
	
	ans = r*g*b;
	
	FOR( i, 1, N ){
		REP( j, N ){
			if( (j+2*i) >= N ) continue;
			if( (S[j] != S[j+i]) && (S[j+i] != S[j+2*i]) && (S[j+2*i] != S[j]) ) ans--;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
