/*
	@・ω・@ <れれですよ
*/

/*****/

# include <iostream>
# include <vector>
# include <algorithm>
# include <string>
# include <cmath>
# include <queue>
# include <stack>
# include <map>
# include <iomanip>	//cout << fixed << setprecision(桁数);
# include <stdexcept>
# include <functional>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<long long, long long>;
template<class T> using vec = vector<T>;

#define debug(x) (std::cerr << x)
#define debugln(x) (std::cerr << x << "\n")
#define debug_tab(n, x) (std::cerr << strMulti("\t",n) << (x) << "\n")
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_coutVec(x) std::cerr << #x << " : "; _debug_coutVec(x)
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(ll i=(n)-1; i >= 0; --i)
#define rrep1(i, n) for(ll i=(n); i > 0; --i)
#define step(i, a, n) for(ll i=(a), i##_len=(a)+(n); i<i##_len; ++i)
#define rstep(i, a, n) for(ll i=(a)+(n)-1, i##_len=(a); i>=i##_len; --i)
#define range(i, a, b) for(ll i=(a), i##_len=(b); i<i##_len; ++i)
#define rrange(i, a, b) for(ll i=(b)-1, i##_len=(a); i>=i##_len; --i)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2147483647;
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = math_P(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool cmp_2nd(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T mod_pow(T x, T n, const T& p) { T ret = 1; while (n > 0) { if (n & 1) { (ret *= x) %= p; } (x *= x) %= p; n >>= 1; } return ret; }
template<class T> T math_gcd(T a, T b) { if (b == 0) { return a; } else { return math_gcd(b, a % b); } }

template<class T> void _debug_coutVec(vector<T> ar, string space = " ") { rep(i, ar.size()) { debug(ar[i] << space); } debugln(""); }

constexpr ll MOD = 1000000007;	// 10e9+7

/*****/

// index が条件を満たすかどうか
template<class T>
bool isOK(vector<T>& list, int index, T key) {
	if (list[index] >= key) { return true; }
	else { return false; }
}

// 汎用的な二分探索のテンプレ
template<class T>
int binary_search(vector<T>& list, T key) {
	int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int ok = (int)list.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	// ok と ng のどちらが大きいかわからないことを考慮
	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (isOK(list, mid, key)) ok = mid;
		else ng = mid;
	}
	return ok;
}

void Main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;

	vec<int> R, G, B;

	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'R')	R.push_back(i);
		if (S[i] == 'G')	G.push_back(i);
		if (S[i] == 'B')	B.push_back(i);
	}

	int RS = R.size(), GS = G.size(), BS = B.size();

	//debug_cout(R);
	//debug_cout(G);
	//debug_cout(B);

	//vec<pair<vec<ll>, ll>> er, er2;

	ll ret = 0;
	for (int r : R)
	{
		//debug_tabcout(0, r);
		for (int g : G)
		{
			//debug_tabcout(1, g);

			ll b_cnt = BS;

			int bi = -1, dif = abs(r - g);
			bi = binary_search(B, dif + max(r, g));
			if (0 <= bi && bi < BS && B[bi] == dif + max(r, g))
			{
				//debug_tabcout(2, C[2][bi]);
				b_cnt--;
				//vec<ll> erp = { r, g, C[2][bi] };
				//sort(all(erp));
				//er.push_back(pair(erp, 0));
			}
			bi = binary_search(B, min(r, g) - dif);
			if (0 <= bi && bi < BS && B[bi] == min(r, g) - dif)
			{
				//debug_tabcout(2, C[2][bi]);
				b_cnt--;
				//vec<ll> erp = { r, g, C[2][bi] };
				//sort(all(erp));
				//er.push_back(pair(erp, 1));
			}
			if ((dif & 1) == 0)
			{
				bi = binary_search(B, dif / 2 + min(r, g));
				if (0 <= bi && bi < BS && B[bi] == dif / 2 + min(r, g))
				{
					//debug_tabcout(2, C[2][bi]);
					b_cnt--;
					//vec<ll> erp = { r, g, C[2][bi] };
					//sort(all(erp));
					//er.push_back(pair(erp, 2));
				}
			}

			//debug_tabcout(1, b_cnt);

			ret += b_cnt;

			/**
			rep(bi2, B)
			{
				ll b = C[2][bi2];

				if (abs(r - g) == abs(g - b) ||
					abs(r - g) == abs(r - b) ||
					abs(r - b) == abs(g - b))
				{
					vec<ll> erp = { r, g, b };
					sort(all(erp));
					er2.push_back(pair(erp, -1));
				}
			}
			/**/
		}
	}

	cout << ret << endl;
}

/*****/

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	//std::cout << std::fixed << std::setprecision(10);

	/**
	while (true)
	{
		Main();
		std::cerr << flush;
		cout << endl;
	}
	/*/
	Main();
	std::cerr << flush;
	cout << endl;
	/**/

	return 0;
}


Measured memory_bytes: 3696