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

#define int ll
#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

ll pow(ll x, ll y) {
	if(y == 0)
	return 1;
	ll temp = pow(x, y/2);
	temp = (temp*temp);
	if(y%2 == 1)
		temp *= x;
	return temp;
}

int32_t main() {
	int n;
	string s;
	cin >> n >> s;
	// vvi pref(n, vi(3, 0));
	// vvi suff(n, vi(3, 0));
	int pref[3] = {0}, suff[3] = {0};
	for(int i = 1; i < n; i++) {
		if(s[i] == 'R')
			suff[0] += 1;
		else if(s[i] == 'G')
			suff[1]++;
		else
			suff[2]++;
	}
	int res = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'R') {
			res += pref[1]*suff[2] + pref[2]*suff[1];
			for(int j = 1; ; j++) {
				if(i + j >= n || i - j < 0)
					break;
				if(s[i + j] == 'G' && s[i - j] == 'B')
					res--;
				if(s[i + j] == 'B' && s[i - j] == 'G')
					res--;
			}
			pref[0]++;
			if(i + 1 < n) {
				if(s[i + 1] == 'R')
					suff[0]--;
				else if(s[i + 1] == 'G')
					suff[1]--;
				else
					suff[2]--;
			}
		}
		if(s[i] == 'G') {
			res += pref[0]*suff[2] + pref[2]*suff[0];
			for(int j = 1; ; j++) {
				if(i + j >= n || i - j < 0)
					break;
				if(s[i + j] == 'R' && s[i - j] == 'B')
					res--;
				if(s[i + j] == 'B' && s[i - j] == 'R')
					res--;
			}
			pref[1]++;
			if(i + 1 < n) {
				if(s[i + 1] == 'R')
					suff[0]--;
				else if(s[i + 1] == 'G')
					suff[1]--;
				else
					suff[2]--;
			}
		}
		if(s[i] == 'B') {
			res += pref[1]*suff[0] + pref[0]*suff[1];
			for(int j = 1; ; j++) {
				if(i + j >= n || i - j < 0)
					break;
				if(s[i + j] == 'G' && s[i - j] == 'R')
					res--;
				if(s[i + j] == 'R' && s[i - j] == 'G')
					res--;
			}
			if(i + 1 < n) {
				if(s[i + 1] == 'R')
					suff[0]--;
				else if(s[i + 1] == 'G')
					suff[1]--;
				else
					suff[2]--;
			}
			pref[2]++;
		}
	}
	cout << res;
}