#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

string t = "RGB";

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> r(n);
	vector<int> g(n);
	vector<int> b(n);
	vector<int> rf(n, 0);
	vector<int> gf(n, 0);
	vector<int> bf(n, 0);
	rep(i, n) {
		if (s[i] == 'R') {
			r[i]++;
			rf[i] = 1;
		}
		if (s[i] == 'G') {
			g[i]++;
			gf[i]++;
		}
		if (s[i] == 'B') {
			b[i]++;
			bf[i]++;
		}
	}
	rep(i, n) {
		if (i > 0) {
			r[i] += r[i - 1];
			g[i] += g[i - 1];
			b[i] += b[i - 1];
		}
	}
	
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (s[i] == s[j]) continue;
			int id;
			int sa = j - i;
			rep(temp, 3) if (t[temp] != s[i] && t[temp] != s[j]) id = temp;
			//jより大きいところにidが何個あるか
			if (id == 0) {
				ans += r[n - 1] - r[j];
				if (sa + j < n && rf[sa + j] == 1) ans--;
			}
			if (id == 1) {
				ans += g[n - 1] - g[j];
				if (sa + j < n && gf[sa + j] == 1) ans--;
			}
			if (id == 2) {
				ans += b[n - 1] - b[j];
				if (sa + j < n && bf[sa + j] == 1) ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

