/*author : Yashvardhan
Sunday, April 12, 2020
5:36 PM
*/

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

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

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

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n;
	cin >> n;

	string s;
	cin >> s;

	vi arr[3];
	map<char,int> mapi = {{'R',0},{'G',1},{'B',2}};
	for(int i = 0; i < n; i++){
		int ind = mapi[s[i]];
		arr[ind].pb(i);
	}

	int ans = 0;
	for(int i = 0; i < n - 2; i++){
		for(int j = i + 2; j < n; j++){
			if(s[i] != s[j]){
				int ind = -1;
				for(int it = 0; it <= 2; it++){
					if(it != mapi[s[i]] && it != mapi[s[j]]){
						ind = it;
						break;
					}
				}
				int l = 0;
				int r = arr[ind].size() - 1;
				int ind1 = -1;

				while(l <= r){
					int mid = (l + r)/2;
					if(arr[ind][mid] > i){
						ind1 = mid;
						r = mid - 1;
					}
					else l = mid + 1;
				}

				l = 0;
				r = arr[ind].size() - 1;
				int ind2 = -1;
				while(l <= r){
					int mid = (l + r)/2;
					if(arr[ind][mid] < j){
						ind2 = mid;
						l = mid + 1;
					}
					else r = mid - 1;
				}

				if(ind1 != -1 && ind2 != -1){
					ans += (ind2 - ind1 + 1);
					if((i + j) % 2 == 0){
						int mid = (i + j) / 2;
						if(mapi[s[mid]] == ind) ans--;
					}
				}
			}
		}
	}
	cout << ans << endl;

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



Measured memory_bytes: 3768