#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

vector<int> ch[3];


int binary_search(int key) {
	int left = 0, right = (int)ch[2].size() - 1; // 配列 a の左端と右端
	while (right >= left) {
		int mid = left + (right - left) / 2; // 区間の真ん中
		if (ch[2][mid] == key) return mid;
		else if (ch[2][mid] > key) right = mid - 1;
		else if (ch[2][mid] < key) left = mid + 1;
	}
	return -1;
}

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

	string s = "";
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			ch[0].push_back(i);
		}
		else if (s[i] == 'G')
		{
			ch[1].push_back(i);
		}
		else
		{
			ch[2].push_back(i);
		}
	}
	long long ll = 0;
	int maxIndex = 0;
	int ass = ch[0].size();
	if (ch[1].size() > ass)
	{
		ass = ch[1].size();
		maxIndex = 1;
	}
	if (ch[2].size() > ass)
	{
		ass = ch[2].size();
		maxIndex = 2;
	}

	if (maxIndex == 0)
	{
		vector<int> tmp = ch[2];
		ch[2] = ch[0];
		ch[0] = tmp;
	}
	else if (maxIndex == 1)
	{
		vector<int> tmp = ch[2];
		ch[2] = ch[1];
		ch[1] = tmp;
	}
	for (int i = 0; i < ch[0].size(); i++)
	{
		for (int j = 0; j < ch[1].size(); j++)
		{
			int mi = min(ch[0][i], ch[1][j]);
			int ma = max(ch[0][i], ch[1][j]);

			int aru = 0;
			if (binary_search(2 * ma - mi) != -1)
			{
				aru++;
			}
			if ((mi + ma) % 2 == 0 && binary_search((mi + ma) / 2) != -1)
			{
				aru++;
			}
			if (binary_search(2 * mi - ma) != -1)
			{
				aru++;
			}

			ll += ch[2].size() - aru;
		}
	}
	cout << ll;
}


Measured memory_bytes: 34672