#include<bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define sz(v) (int) v.size()
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int MAX_N = 4005;

int n;
string s;
int pref[MAX_N][26];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		if (i) for (int j = 0; j < 26; ++j) pref[i][j] = pref[i - 1][j];
		pref[i][s[i] - 'A']++;
	}
	ll ans = 0;
	for (int j = 1; j < n; ++j) {
		for (int k = j + 1; k < n; ++k) {
			if (s[j] == s[k]) continue;
			if ('R' != s[j] && 'R' != s[k]) {
				ans += pref[j - 1]['R' - 'A'];
				if (2 * j - k > -1 && s[2 * j - k] == 'R') ans--;
			} else if ('G' != s[j] && 'G' != s[k]) {
				ans += pref[j - 1]['G' - 'A'];
				if (2 * j - k > -1 && s[2 * j - k] == 'G') ans--;
			} else {
				ans += pref[j - 1]['B' - 'A'];
				if (2 * j - k > -1 && s[2 * j - k] == 'B') ans--;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}