#include <bits/stdc++.h>
using namespace std;

#define ipr pair<int, int>
#define pb push_back
#define ff first
#define ss second
#define fr(i, j, k) for (int i = j; i < k; i++)
#define rf(i, j, k) for (int i = j; i >= k; i--)
#define int long long
#define ll unsigned long long
#define ld long double
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define inf 1000000000000000000
#define cnt_ones(x) __builtin_popcountll(x)

#define IOS                           \
	std::ios::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);

const int Maxn = 100001;
const ld pi = acos(-1);
const int mod = 998244353;

template <class T>
ostream &operator<<(ostream &out, vector<T> &A)
{
	for (auto x : A)
		out << x << " ";
	return out;
}

int32_t main(){IOS
	int Q=1;	//cin>>Q;
	while(Q--){
		int n;	cin>>n;
		string s;	cin>>s;
		vector<vector<int> >A(n, vector<int> (3, 0));
		if(s[n-1] == 'R')	A[n-1][0]++;
		else if(s[n-1] == 'B') A[n-1][1]++;
		else    A[n-1][2]++;
		rf(i,n-2,0){
			fr(k, 0, 3)
				A[i][k] += A[i + 1][k];
			if(s[i] == 'R')	A[i][0]++;
			else if(s[i] == 'B') A[i][1]++;
			else    A[i][2]++;
		}
		int ans = 0;
		fr(i,0,n-2)	fr(j,i+1,n-1)
		if(s[i] != s[j]){
			if(j+j-i < n and s[j+j-i]!=s[j] and s[j+j-i]!=s[i])	ans--;
			bool red=false, blue=false, green=false;
			if(s[i] == 'R' or s[j] == 'R')	red=true;
			if(s[i] == 'B' or s[j] == 'B')	blue=true;
			if(s[i] == 'G' or s[j] == 'G')	green=true;
			if(!red)	ans += A[j+1][0];
			else if(!blue)	ans += A[j+1][1];
			else ans += A[j+1][2];
		}
		cout << ans << '\n';
	} 
	return 0;
}