#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
#define MAX 200000
#define NIL -1

int N;
string S;


int ans;
int R[4000],G[4000],B[4000];



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	cin >> S;

	FOR(i, 0, N) {
		if (S[i] == 'R')R[i]++;
		if (S[i] == 'G')G[i]++;
		if (S[i] == 'B')B[i]++;
		if (i != 0) {
			R[i] += R[i - 1];
			G[i] += G[i - 1];
			B[i] += B[i - 1];
		}
	}

	FOR(j, 1, N-1) {
		FOR(k, j+1, N) {
			if (S[j] == S[k])continue;

			if (S[j] != 'R'&&S[k] != 'R')ans += R[j - 1];
			if (S[j] != 'G'&&S[k] != 'G')ans += G[j - 1];
			if (S[j] != 'B'&&S[k] != 'B')ans += B[j - 1];

			int i = j * 2 - k;
			if (i >= 0) {
				if (S[i] != S[j] && S[i] != S[k])ans--;
			}


		}
	}

	cout << ans << endl;

	return 0;
}
