#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;
V<V<int> > v;

ll f(int a, int b, int c) {
	ll ans = 0;
	REP(i, v[a].size()) {
		REP(j, v[b].size()) {
			if(v[a][i] > v[b][j]) break;
			REP(k, v[c].size()) {
				if(v[b][j] > v[c][k]) break;
				if(v[b][j]-v[a][i] == v[c][k]-v[b][j]) continue;
				// cout << v[a][i] << " " << v[b][j] << " " << v[c][k] << endl;
				ans += 1;
			}
		}
	}
	return ans;
}

int main() {
	ll n, ans = 0;
	string s;

	cin >> n;
	cin >> s;

	REP(i,3) {
		V<int> a;
		v.push_back(a);
	}

	FORD(i,n-1,0) {
		if(s[i] == 'R') {
			v[0].push_back(i);
		} else if (s[i] == 'G') {
			v[1].push_back(i);
		} else if (s[i] == 'B') {
			v[2].push_back(i);
		}
	}
	ans += f(0,1,2);
	ans += f(0,2,1);
	ans += f(1,0,2);
	ans += f(1,2,0);
	ans += f(2,0,1);
	ans += f(2,1,0);

	// REP(i,3) {
	// 	REP(j,v[i].size()) {
	// 		cout << v[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	cout << ans << endl;
	return 0;

}

