#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

ll factorial(ll a) {
	ll ans = 1;
	for (ll i = 1; i <= a; i++) {
		ans *= i;
	}
	return ans;
}

int main() {
	//答えは(条件Aを満たすもの)-(条件Bを満たさないが条件Aを満たすもの)である
	int n;
	string s;
	cin >> n >> s;
	ll times_R = 0;
	ll times_G = 0;
	ll times_B = 0;
	rep(i, n) {
		if (s[i] == 'R') {
			times_R++;
		}
		else if (s[i] == 'G') {
			times_G++;
		}
		else times_B++;
	}

	ll ans = times_R * times_G * times_B;

	//以下のループ内は条件Bを満たさないもの
	rep(start, n - 2) {
		for (int space = start + 1; space + (space - start) < n; space++) {
			if (
				s[start] != s[space]
				&& s[space] != s[space + (space - start)]
				&& s[start] != s[space + (space - start)]
				) ans--;
		}
	}

	cout << ans << endl;
	return 0;
}