#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define int ll
#define mpp make_pair
#define endl '\n'
#define ff first 
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 5e5 + 5;
const int MAXN = 1e5 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

void solve() 
{
	int n;
	cin >> n;
	string input;
	cin >> input;
	vector<int> v;
	v.push_back(0);
	map<char, int> mp;
	mp['R'] = 1;
	mp['G'] = 2;
	mp['B'] = 3;
	for(int x : input)
	{
		v.push_back(mp[x]);
	}
	vector<int> pref1(n + 1, 0);
	vector<int> pref2(n + 1, 0);
	vector<int> pref3(n + 1, 0);
	for(int i = 1; i <= n; i++)
	{
		if(v[i] == 1)
		{
			pref1[i]++;
		}
		else if(v[i] == 2)
		{
			pref2[i]++;
		}
		else
		{
			pref3[i]++;
		}
		pref1[i] += pref1[i - 1];
		pref3[i] += pref3[i - 1];
		pref2[i] += pref2[i - 1];
	}
	int ret = 0;
	for(int i = 1; i <= n; i++)
	{
		for(int j = i + 1; j <= n; j++)
		{
			if(v[i] != v[j])
			{
				int a = v[i];
				int b = v[j];
				int X = (1 ^ 2) ^ 3;
				int found = (X ^ a) ^ b;
				// trace(i, j, found);
				int freq = 0;
				if(found == 1)
				{
					freq = pref1[n] - pref1[j];
				}
				else if(found == 2)
				{
					freq = pref2[n] - pref2[j];
				}
				else
				{
					freq = pref3[n] - pref3[j];
				}
				// trace(i, j, found, freq, 2 * j - i);
				if(2 * j - i <= n and v[2 * j - i] == found)
				{
					freq--;
				}
				ret += freq;
			}
		}
	}
	cout << ret << endl;
}

 
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3760