#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/
//ll nx[2000000] = {0};
//ll cur[2000000] = {0};

string concat(string l, string r, int n) {
	int ll=l.size();
	int rl=r.size();
	string ret = ""+l;
	for(int i=n;i<ll&&i-n<rl;++i)
	{
		if(ret[i]=='?' && r[i-n]!='?')
		{
			ret[i] = r[i-n];
		}
	}
	if(n+rl > ll)
		ret += r.substr(ll-n);
	return ret;
}


int main()
{
	ll ans = 0;
	ll N,T=1, M;
	string S;
	ll mpl[4096][3] = {0};
	ll mpr[4096][3] = {0};
	cin >> N;
	cin >> S;
	for(int i = 0; i< N; ++i)
	{
		if(S[i] == 'R')
			mpl[i][0] = 1;
		else if(S[i] == 'G')
			mpl[i][1] = 1;
		else
			mpl[i][2] = 1;
		if(i > 0)
		{
			mpl[i][0] += mpl[i-1][0];
			mpl[i][1] += mpl[i-1][1];
			mpl[i][2] += mpl[i-1][2];
		}
	}
	for(int i = N-1; i>=0; --i)
	{
		if(S[i] == 'R')
			mpr[i][0] = 1;
		else if(S[i] == 'G')
			mpr[i][1] = 1;
		else
			mpr[i][2] = 1;
		if(i < N-1)
		{
			mpr[i][0] += mpr[i+1][0];
			mpr[i][1] += mpr[i+1][1];
			mpr[i][2] += mpr[i+1][2];
		}
	}
	for(int i = 1; i < N - 1; ++i)
	{
		if(S[i] == 'R')
		{
			ans += mpl[i-1][1] * mpr[i+1][2];
			ans += mpl[i-1][2] * mpr[i+1][1];
		}
		else if(S[i] == 'G')
		{
			ans += mpl[i-1][0] * mpr[i+1][2];
			ans += mpl[i-1][2] * mpr[i+1][0];
		}
		else
		{
			ans += mpl[i-1][1] * mpr[i+1][0];
			ans += mpl[i-1][0] * mpr[i+1][1];
		}
	}
	for(int i = 1;i < N-1; ++i)
	{
		for(int j = 0; j < i ; ++j)
		{
			if(i*2-j >= N)
				continue;
			if(S[j] != S[i] && S[j] != S[i*2-j] && S[i] != S[i*2-j])
			{
				//cout << i << " " << j << " " << 2*i-j << endl;
				ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 3828