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

#define ll long long
#define vec vector<ll>
#define rev(a); reverse(a.begin(), a.end());
#define sorta(a); sort(a.begin(), a.end());
#define sortd(a); sort(a.begin(), a.end(), greater<int>());
#define FOR(i,a,b) for (ll i = (ll)(a); i < (b); i++)
#define ROF(i,a,b) for (ll i = (ll)(b)-1; i >= (a); i--)
#define printarray(a) FOR(Q,0,(int)(a).size()) cout<<(a)[Q]<<" "; cout<<'\n';
#define pb push_back
#define mp make_pair

ll MOD = 1000000007;
ll INF = 1LL << 60;

/*****************************************************************************/


bool same(int i, char c) {
	return ((i==0 && c=='R') || (i==1 && c=='G') || (i==2 && c=='B'));
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;cin>>n;
	string s;cin>>s;
	int cum[n][3];
	FOR(i,0,n) FOR(j,0,3) cum[i][j]=0;
	vector<set<int>> ind (3);
	FOR(i,0,n) {
		if (s[i]=='R') {
			cum[i][0]++;
			ind[0].insert(i);
		}
		if (s[i]=='G') {
			cum[i][1]++;
			ind[1].insert(i);
		}
		if (s[i]=='B') {
			cum[i][2]++;
			ind[2].insert(i);
		}
		if (i==0) continue;
		FOR(j,0,3) {
			cum[i][j]+=cum[i-1][j];
		}
	}

	FOR(j,0,3) {
		FOR(i,0,n) {
			cum[i][j] = cum[n-1][j] - cum[i][j];
			if (same(j, s[i])) cum[i][j]++;
		}
	}

	// FOR(i,0,n) cout<<cum[i][0]<<" ";cout<<endl;
	// for(int i : ind[0]) cout<<i<<" ";
	
	ll out=0;
	FOR(i,0,3) {
		FOR(j,0,3) {
			if (i==j) continue;
			int k=-1;
			FOR(l,0,3) {
				if (l!=i&&l!=j) {
					k=l;
					break;
				}
			}

			FOR(a,0,n-2) {
				if (!same(i,s[a])) continue;
				FOR(b,a+1,n-1) {
					if (!same(j,s[b])) continue;
					out += cum[b+1][k];
					int s = b-a;
					s = b+s;
					if (ind[k].count(s)) {
						out--;
					}
				}
			}
		}
	}

	cout<<out;
}