#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define LEN(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

int n,i,j,k,m;
string s;
char c;
ll ans;

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >>n >>s;
	for (i=0;i<n-2;j++) {
		for (j=i+1;j<n-1;j++) {
			if (s[i]==s[j]) continue;
			m=j-i;
			if (s[i]!='R' && s[j]!='R') c='R';
			if (s[i]!='G' && s[j]!='G') c='G';
			if (s[i]!='B' && s[j]!='B') c='B';
			for (k=j+1;k<n;k++) {
				if (s[k]==c && k-j==m) ans++;
			}
		}
	}
	cout <<ans;
	return 0;
}
/******************************************************************************
******************************************************************************/
