#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 10;

int rui[3][4005];
int rev_rui[3][4005];

int N;
string S;

signed main()
{
	cin>>N>>S;
	S=' '+S;
	for (int i=1;i<=N;++i) {
		rep(j, 3) {
			rui[j][i] = rui[j][i-1];
		}
		if (S[i]=='R')rui[0][i]++;
		if (S[i]=='G')rui[1][i]++;
		if (S[i]=='B')rui[2][i]++;
	}
	for (int i=N;i>=1;--i) {
		rep(j, 3) {
			rev_rui[j][i] = rev_rui[j][i+1];
		}
		if (S[i]=='R')rev_rui[0][i]++;
		if (S[i]=='G')rev_rui[1][i]++;
		if (S[i]=='B')rev_rui[2][i]++;
	}

	int ans = 0;

	for (int i = 2; i <= N - 1; ++i) {
		if (S[i] == 'R') {
			for (int diff = 1; i + diff <= N; ++diff) {
				if (S[i + diff] == 'G') {
					int B = rui[2][i - 1];
					if (i - diff >= 0) B -= rui[2][i - diff];
					if (i - diff - 1 >= 0) B += rui[2][i - diff - 1];
					ans += B;
				}
				if (S[i + diff] == 'B') {
					int G = rui[1][i - 1];
					if (i - diff >= 0) G -= rui[1][i - diff];
					if (i - diff - 1 >= 0) G += rui[1][i - diff - 1];
					ans += G;
				}
			}
		}
		if (S[i] == 'G') {
			for (int diff = 1; i + diff <= N; ++diff) {
				if (S[i + diff] == 'R') {
					int B = rui[2][i - 1];
					if (i - diff >= 0) B -= rui[2][i - diff];
					if (i - diff - 1 >= 0) B += rui[2][i - diff - 1];
					ans += B;
				}
				if (S[i + diff] == 'B') {
					int R = rui[0][i - 1];
					if (i - diff >= 0) R -= rui[0][i - diff];
					if (i - diff - 1 >= 0) R += rui[0][i - diff - 1];
					ans += R;
				}
			}
		}
		if (S[i] == 'B') {
			for (int diff = 1; i + diff <= N; ++diff) {
				if (S[i + diff] == 'R') {
					int G = rui[1][i - 1];
					if (i - diff >= 0) G-= rui[1][i - diff];
					if (i - diff - 1 >= 0) G+= rui[1][i - diff - 1];
					ans += G;
				}
				if (S[i + diff] == 'G') {
					int R = rui[0][i - 1];
					if (i - diff >= 0) R -= rui[0][i - diff];
					if (i - diff - 1 >= 0) R += rui[0][i - diff - 1];
					ans += R;
				}
			}
		}
	}

	cout << ans << endl;
}


