#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <stdio.h>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
//constexpr ll MOD = (1e9 + 7);
constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

//template<class T>vector<T> vec(size_t a) { return vector<T>(a); }

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

ll maxVec(vector<ll> &v) {
	ll ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

ll moddiv(ll n, ll a,ll m) {
	if (a == 0)return 1;
	if (a % 2 == 0) {
		ll b = moddiv(n, a / 2, m);
		return (b * b) % m;
	}
	else if (a % 2 == 1) return (n * moddiv(n, a - 1, m)) % m;
}

// グラフは<頂点,コスト>
void Dijkstra(ll v, vector<vector<pll>> graph,ll s, vl& ans) {
	auto comp = [](const pll a, const pll b) { return a.first > b.first; };
	priority_queue<pll, vector<pll>, decltype(comp)> que(comp);
	ans = vl(v, INF);
	ans[s] = 0;
	que.push(pll{ 0, s });
	pll a;
	while (!que.empty()) {
		ll c = que.top().first, p = que.top().second;
		que.pop();
		rep(i,0, graph[p].size()) {
			a = graph[p][i];
			if (ans[a.first] > a.second + c) {
				ans[a.first] = a.second + c;
				que.push(pll{ a.second + c,a.first });
			}
		}
	}
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}

// 素因数分解
void factorization(ll n, vector<pll> &ans) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0)ans.push_back(make_pair(i, 0));
		while (n % i == 0) {
			ans.back().second++;
			n /= i;
		}
	}
	if (n != 1) ans.push_back(make_pair(n, 1));
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

ll euclidean_gcd(ll a, ll b) {
	if (a < b) return euclidean_gcd(b, a);
	ll r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

ll dp[4003][3];

ll henkan(char c,char b) {
	if (c == 'R' && b == 'G')return 2;
	if (c == 'G' && b == 'B')return 0;
	if (c == 'B' && b == 'R')return 1;
	return henkan(b, c);
}

int main() {
	ll n;
	string s;
	cin >> n;
	cin >> s;
	//ll i = 0, j = 1, k = 2;
	for (ll a = n - 1; a >= 0; a--) {
		ll c = 0;
		if (s[a] == 'G') {
			dp[a][1] = dp[a + 1][1] + 1;
			dp[a][0] = dp[a + 1][0];
			dp[a][2] = dp[a + 1][2];
		}
		else if (s[a] == 'B') {
			dp[a][1] = dp[a + 1][1];
			dp[a][0] = dp[a + 1][0];
			dp[a][2] = dp[a + 1][2] + 1;

		}
		else{
			dp[a][1] = dp[a + 1][1];
			dp[a][0] = dp[a + 1][0] + 1;
			dp[a][2] = dp[a + 1][2];

		}
	}
	ll ans = 0;
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			if (s[i] != s[j]) {
				ans += dp[j + 1][henkan(s[i], s[j])];
				//cout <<i<<j<< dp[j + 1][henkan(s[i], s[j])] << "\n";
				if (j + j - i < n) {
					if (s[j + j - i] != s[j] && s[j + j - i] != s[i]) {
						ans--;
						//cout << i << j << "\n";
					}
				}
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3700