#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int INF = 1001001001;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

int gcd(int a, int b) {
	if (a < b) {
		int c = a;
		a = b;
		b = c;
	}
	if (b == 0) return a;
	return gcd (b, a % b);
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;

	vector<int> rv, gv, bv;
	int r = 0, g = 0, b = 0;
	rep(i,n) {
		if (s.at(i) == 'R') {
			rv.push_back(i + 1);
			r++;
		}
		if (s.at(i) == 'G') {
			gv.push_back(i + 1);
			g++;
		}
		if (s.at(i) == 'B') {
			bv.push_back(i + 1);
			b++;
		}
	}
	if (r*g*b == 0) return 0;
	int cnt = 0, RGB;
	RGB = 'R' + 'G' + 'B';
	for (int i = 1; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s.at(i - 1) == s.at(j - 1)) {
				continue;
			}
			int rem;
			rem = s.at(i - 1) + s.at(j - 1);
			vector<int> range;
			if (RGB - rem == 'R') {
				range.resize(rv.size());
				copy(rv.begin(), rv.end(), range.begin());
			}
			if (RGB - rem == 'G') {
				range.resize(gv.size());
				copy(gv.begin(), gv.end(), range.begin());
			}
			if (RGB - rem == 'B') {
				range.resize(bv.size());
				copy(bv.begin(), bv.end(), range.begin());
			}
			for (auto k : range) {
				if (j >= k) continue;
				if (2*j == (i + k)) continue;
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}
