// Problem : D - RGB Triplets
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n; i >= a; i--)
#define pb              push_back
#define lb              lower_bound		// first element >= val(itr) 
#define ub              upper_bound		// first element >  val(itr)
#define vll							vector<ll>
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))	//x can be 0 or -1

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

#ifdef LOCAL_TEST
#include"/home/shrey/debug.h"
#endif

const ll inf = 1e18;
const int nax = 1e5 + 5;

void SolveTestCase()
{
	ll n;
	cin>>n;
	
	string s;
	cin>>s;
	
	ll ans = 0;
	vector<ll>arr[3];
	forn(i,0,n)
	{
		if(s[i] == 'R')
		{
			arr[0].pb(i);
		}
		else if(s[i] == 'G')
		{
			arr[1].pb(i);
		}
		else
		{
			arr[2].pb(i);
		}
	}
	
	forn(i,0,n)
	{
		forn(j,i+1,n)
		{
			if((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
			{
					ll num = arr[2].size();
					ll idx = lb(all(arr[2]),2*j-i+1) - arr[2].begin();
					if(idx<num)
					{
						ans += (num-idx);
					}
					
					ll idx1,idx2;
					idx1 = lb(all(arr[2]),2*j-i) - arr[2].begin();
					idx2 = lb(all(arr[2]),j+1) - arr[2].begin();
					
					if(idx1<num && idx2<num)
					{
						ans += (idx1-idx2);
					}
					else if(idx2<num)
					{
						ans += (num-idx2);
					}
			}
			else if((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
			{
				  ll num = arr[1].size();
					ll idx = lb(all(arr[1]),2*j-i+1) - arr[1].begin();
					if(idx<num)
					{
						ans += (num-idx);
					}
					
					ll idx1,idx2;
					idx1 = lb(all(arr[1]),2*j-i) - arr[1].begin();
					idx2 = lb(all(arr[1]),j+1) - arr[1].begin();
					
					if(idx1<num && idx2<num)
					{
						ans += (idx1-idx2);
					}
					else if(idx2<num)
					{
						ans += (num-idx2);
					}
			}
			else if((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G'))
			{
					ll num = arr[0].size();
					ll idx = lb(all(arr[0]),2*j-i+1) - arr[0].begin();
					if(idx<num)
					{
						ans += (num-idx);
					}
					
					ll idx1,idx2;
					idx1 = lb(all(arr[0]),2*j-i) - arr[0].begin();
					idx2 = lb(all(arr[0]),j+1) - arr[0].begin();
					
					if(idx1<num && idx2<num)
					{
						ans += (idx1-idx2);
					}
					else if(idx2<num)
					{
						ans += (num-idx2);
					}
			}
		}
	}
	
	cout<<ans;
}

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	forn(i, 0, t)
	{
		SolveTestCase();
	}

	return 0;
}


Measured memory_bytes: 3696