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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;
	string s;
	cin >> s;

	int r = count(all(s),'R');
	int g = count(all(s),'G');
	int b = count(all(s),'B');
	ll ans = r * g * b;
	cerr << ans << endl;
	rep(i, n){
		rep(j, i){
			int k = 2*i - j;
			if(k < n){
				if(s[i] == s[j]) continue;
				if(s[i] == s[k]) continue;
				if(s[j] == s[k]) continue;
				ans--;
			}
		}
	}

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