#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 4001

int N;
string S;

map <char,int> idx = {{'R',0},{'G',1},{'B',2}};

int dp[maxn][(1<<4)];

int dpf(int i,int bm){
	if (dp[i][bm] != -1) return dp[i][bm];
	
	if (bm == (1<<3) - 1) return 1;
	if (i == N) return 0;
	
	if (bm & (1<<idx[S[i]])) dp[i][bm] = dpf(i + 1, bm);
	else dp[i][bm] = dpf(i + 1,bm) + dpf(i + 1, bm | (1<<idx[S[i]]));
	
	return dp[i][bm];
}

int main(){
	fast;
	
	cin>>N>>S;
	
	mem(dp,-1);
	
	
	
	int ans = dpf(0,0);
	
	FOR(i,0,N-1){
		FOR(j,i+1,N-1){
			if (S[i] == S[j]) continue;
			
			int k = j + (j - i);
			
			if (k < N && S[k] != S[i] && S[k] != S[j]){
				//cout<<i<<' '<<j<<' '<<k<<'\n';
				ans--;
			}
		}
		
	}
	
	cout<<ans;
				
}

