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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 500000000000000;
constexpr auto MOD = 1000000007;


int main() {
	int n;
	string s;
	cin >> n >> s;

	vi r = {}, g = {}, b = {};

	rep(i, n){
		if (s[i] == 'R')r.push_back(i);
		if (s[i] == 'G')g.push_back(i);
		if (s[i] == 'B')b.push_back(i);
	}
	ll ans=0;

	rep(i, r.size())rep(j, g.size()) {

		if (b.size() == 0)break;

		ans += b.size();

		if ((r[i] + g[j]) % 2 == 0 && s[(r[i] + g[j]) / 2] == 'B')ans--;
		
		int le = min(r[i], g[j]) - abs(r[i] - g[j]);
		int ri = max(r[i], g[j]) + abs(r[i] - g[j]);

		if (n - 1 >= le && le >= 0)if (s[le] == 'B') ans--;
		if (0 <= ri && ri <= n - 1)if (s[ri] == 'B') ans--;
	}

	cout << ans << endl;
}