#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (ll)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll N;
	string S;
	cin >> N >> S;

	ll rNum = 0;
	ll gNum = 0;
	ll bNum = 0;
	REP(i, N) {
		if (S[i] == 'R') rNum++;
		if (S[i] == 'G') gNum++;
		if (S[i] == 'B') bNum++;
	}
	ll ans = rNum * gNum * bNum;

	ll renzoku = 0;
	REP(i, N) {
//		ll lim = N /3 + 1;
		REPN(j, 1, N) {
			if (N <= i + j) continue;
			if (N <= i + j * 2) continue;
			char a = S[i];
			char b = S[i + j];
			char c = S[i + j * 2];
			if (a != b && b != c && c != a) {
				renzoku++;
			}
		}
	}

	ans -= renzoku;
	cout << ans << endl;
	return 0;
}
