#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> sumr(n + 1);
	vector<int> sumg(n + 1);
	vector<int> sumb(n + 1);
	rep(i, n) {
		if (s[i] == 'R') sumr[i]++;
		if (s[i] == 'G') sumg[i]++;
		if (s[i] == 'B') sumb[i]++;
		sumr[i + 1] += sumr[i];
		sumg[i + 1] += sumg[i];
		sumb[i + 1] += sumb[i];
	}
	int ans = 0;
	rep(i, n - 1) {
		for (int j = i + 1; j < n; ++j) {
			if (s[i] == 'R' && s[j] == 'G') {
				int tmp = sumb[n] - sumb[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'B') ans--;
			}
			if (s[i] == 'G' && s[j] == 'R') {
				int tmp = sumb[n] - sumb[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'B') ans--;
			}
			if (s[i] == 'R' && s[j] == 'B') {
				int tmp = sumg[n] - sumg[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'G') ans--;
			}
			if (s[i] == 'B' && s[j] == 'R') {
				int tmp = sumg[n] - sumg[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'G') ans--;
			}
			if (s[i] == 'G' && s[j] == 'B') {
				int tmp = sumr[n] - sumr[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'R') ans--;
			}
			if (s[i] == 'B' && s[j] == 'G') {
				int tmp = sumr[n] - sumr[j];
				ans += tmp;
				if (2 * j - i > n) continue;
				if (s[2 * j - i] == 'R') ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}
