#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	int N=in();
	string S=in<string>();
	vector<vector<int>> C(3);
	REP(i,N){
		if(S[i]=='R') C[0].push_back(i);
		if(S[i]=='G') C[1].push_back(i);
		if(S[i]=='B') C[2].push_back(i);
	}
	int NR=C[0].size(),NG=C[1].size(),NB=C[2].size();
	ll A=0;
	REP(i,NR){
		REP(j,NG){
			int R=C[0][i],G=C[1][j];
			int DA = G-R;
			if(DA<=0) continue;

			auto pos = lower_bound(ALL(C[2]),G);
			auto dist = distance(C[2].begin(),pos);
			int Q = G+DA;
			auto res = binary_search(ALL(C[2]),Q);
			if(res) A += max<size_t>(C[2].size()-(size_t)1-dist,(size_t)(0));
			else A += max<size_t>(C[2].size()-dist,(size_t)0);
		}
		REP(j,NB){
			int R=C[0][i],B=C[2][j];
			int DA = B-R;
			if(DA<=0) continue;

			auto pos = lower_bound(ALL(C[1]),B);
			auto dist = distance(C[1].begin(),pos);
			int Q = B+DA;
			auto res = binary_search(ALL(C[1]),Q);
			if(res) A += max<size_t>(C[1].size()-(size_t)1-dist,(size_t)0);
			else A += max<size_t>(C[1].size()-dist,(size_t)0);
		}
	}
	REP(i,NG){
		REP(j,NR){
			int G=C[1][i],R=C[0][j];
			int DA = R-G;
			if(DA<=0) continue;

			auto pos = lower_bound(ALL(C[2]),R);
			auto dist = distance(C[2].begin(),pos);
			int Q = R+DA;
			auto res = binary_search(ALL(C[2]),Q);
			if(res) A += max<size_t>(C[2].size()-(size_t)1-dist,(size_t)0);
			else A += max<size_t>(C[2].size()-dist,(size_t)0);
		}
		REP(j,NB){
			int G=C[1][i],B=C[2][j];
			int DA = B-G;
			if(DA<=0) continue;

			auto pos = lower_bound(ALL(C[0]),B);
			auto dist = distance(C[0].begin(),pos);
			int Q = B+DA;
			auto res = binary_search(ALL(C[0]),Q);
			if(res) A += max<size_t>(C[0].size()-(size_t)1-dist,(size_t)0);
			else A += max<size_t>(C[0].size()-dist,(size_t)0);
		}
	}
	REP(i,NB){
		REP(j,NR){
			int B=C[2][i],R=C[0][j];
			int DA = R-B;
			if(DA<=0) continue;

			auto pos = lower_bound(ALL(C[1]),R);
			auto dist = distance(C[1].begin(),pos);
			int Q = R+DA;
			auto res = binary_search(ALL(C[1]),Q);
			if(res) A += max<size_t>(C[1].size()-(size_t)1-dist,(size_t)0);
			else A += max<size_t>(C[1].size()-dist,(size_t)0);
		}
		REP(j,NG){
			int B=C[2][i],G=C[1][j];
			int DA = G-B;
			if(DA<=0) continue;

			auto pos = lower_bound(ALL(C[0]),G);
			auto dist = distance(C[0].begin(),pos);
			int Q = G+DA;
			auto res = binary_search(ALL(C[0]),Q);
			if(res) A += max<size_t>(C[0].size()-(size_t)1-dist,(size_t)0);
			else A += max<size_t>(C[0].size()-dist,(size_t)0);
		}
	}
	out(A);
	return 0;
}


Measured memory_bytes: 3696