#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	ll ans = 0;
	vector<vector<int>>rgb(3, vector<int>(N, 0));
	rep(i, 0, N) {
		if (s[i] == 'R')rgb[0][i]++;
		if (s[i] == 'G')rgb[1][i]++;
		if (s[i] == 'B')rgb[2][i]++;
	}
	rep(i, 1, N) {
		rgb[0][i] += rgb[0][i - 1];
		rgb[1][i] += rgb[1][i - 1];
		rgb[2][i] += rgb[2][i - 1];
	}
	char ch[] = { 'R','G','B' };
	rep(i, 0, N) {
		rep(j, i + 1, N) {
			if (s[i] == s[j])continue;
			int x;
			rep(k, 0, 3)if (s[i] != ch[k] && s[j] != ch[k])x = k;
			ll comb = rgb[x][j - 1] - rgb[x][i] + rgb[x][N - 1] - rgb[x][j];

			if ((i + j)%2 == 0) {
				if (s[(i + j) / 2] == ch[x])comb--;
			}
			int k = 2 * j - i;
			if (k < N && s[k] == ch[x])--comb;
			ans += comb;
		}
	}
	cout << ans / 2 << "\n";

	return 0;
}