#include <bits/stdc++.h>

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
ll mod(ll a, ll b) {return (a % b + b) % b;}

using namespace std;


int main() 
{	
	fast;
	ll n; cin>>n;
	string s; cin>>s;
	vector<ll>r,g,b;
	for(ll i = 0; i < s.size(); i++)
	{
		if(s[i] == 'R') r.push_back(i+1);
		else if(s[i] == 'G') g.push_back(i+1);
		else b.push_back(i+1);
	} 
	ll ans = r.size() * g.size() * b.size();
//	for(auto &a : r) cout << a << " "; cout << endl;
//	for(auto &a : g) cout << a << " "; cout << endl;
//	for(auto &a : b) cout << a << " "; cout << endl;
	for(ll i = 0; i < r.size(); i++)
	{
		for(ll j = 0; j < g.size(); j++)
		{
			
			for(ll k = 0; k < b.size(); k++)
			{
				if(2*r[i]==g[j]+b[k] || 2*g[j]==r[i]+b[k] || 2*b[k]==r[i]+g[j])ans--;
			}
		}
	}
	cout << ans << endl;
	return 0;
}