#include <iostream>
#include <queue>
#include <map>
#include <bitset>
#include <string>
#include <set>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <stack>
#include <cstdlib>
#include <numeric>
#include <cassert>
#include <complex>
#include <iterator>
//#include <unordered_map>
using namespace std;
#define maxn 500007
#define maxm 400007
#define maxq 1000007
#define maxl 1234
#define modn 998244353 
#define scan(a) scanf("%d",&a)
#define scanl(a) scanf("%lld",&a)
#define scanl2(a,b) scanf("%lld%lld",&a,&b)
#define scans(a) scanf("%s",a)
#define scans2(a,b) scanf("%s%s",a,b)
#define scand(a) scanf("%lf",&a)
#define scan2(a,b) scanf("%d%d",&a,&b)
#define scand2(a,b) scanf("%lf%lf",&a,&b)
#define scan3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scan4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scan5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define print(a) printf("%d\n",a);
#define printl(a) printf("%lld\n",a);
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,a,b) for(int i=a;i>= b;i--)
#define fscan(a) fscanf(stream,"%d", &a);
#define mp      make_pair	
#define pb      push_back
#define eb      emplace_back
#define mm(a,b) memset(a,b,sizeof a)
#define log2(n) (double)(log(n) / log(2.0))
#define _crt_disable_perfcrit_locks
#define bll __int128
#pragma warning(disable:4996)
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef map <int, int> mii;
typedef pair <int, int> pii;
typedef map <char, int> mci;
typedef map <char, char> mcc;
typedef pair <char, int> pci;
typedef complex<double> cd;
typedef vector<complex<double> > vcd;
const double eps = 1e-8;
const double PI = 2 * acos(0.0);

int cc, bb; char ch; inline int F() {
	while (ch = getchar(), (ch < 48 || ch> 57) && ch != '-'); ch == '-' ? cc = bb = 0 : (cc = ch - '0', bb = 1);
	while (ch = getchar(), ch > 47 && ch < 58)cc = (cc << 1) + (cc << 3) + (ch ^ 48); return bb ? cc : -cc;
}
void write(int x) {
	int y = 10, len = 1;
	while (y <= x) { y *= 10; len++; }
	while (len--) { y /= 10; putchar(x / y + 48); x %= y; }
}
ll pow2(ll a, ll b, ll mod) {
	ll r = 1, base = a;
	while (b) {
		if (b & 1) r = r * base % mod;
		base = base * base % mod;
		b >>= 1;
	}
	return r;
}
ll inv(ll a, ll n) {
	return pow2(a, n - 2, n);
	//return pow2(a, oula(n) - 1, n);
}
ll gcd(ll a, ll b) {
	ll r;
	while (b != 0) {
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}
int n;
string s;
int sR[4007], sG[4007], sB[4007];
int main() {
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	//FILE* stream = fopen("L:/20.in", "rb+")
	cin >> n;
	cin >> s;
	if (n <= 3) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = n - 2; i >= 0; i--) {
		sR[i] = sR[i + 1];
		sG[i] = sG[i + 1];
		sB[i] = sB[i + 1];
		if (s[i + 1] == 'R')sR[i]++;
		if (s[i + 1] == 'G')sG[i]++;
		if (s[i + 1] == 'B')sB[i]++;
	}
	int k;
	ll res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < i; j++) {
			if (s[i] != s[j]) {
				k = (i << 1) - j;
				if (k < n && s[i] != s[k] && s[j] != s[k])
					res--;
				if (s[i] == 'R' && s[j] == 'G')
					res += sB[i];
				else if (s[i] == 'R' && s[j] == 'B')
					res += sG[i];
				else if (s[i] == 'G' && s[j] == 'R')
					res += sB[i];
				else if (s[i] == 'G' && s[j] == 'B')
					res += sR[i];
				else if (s[i] == 'B' && s[j] == 'R')
					res += sG[i];
				else if (s[i] == 'B' && s[j] == 'G')
					res += sR[i];
			}
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3676