#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<numeric>
#include<cmath>
#include<cstring>
#include<deque>
#include<map>
#include<iomanip>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int,int>>
#define ll long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{ {-1,0},{1,0},{0,-1},{0,1} };
const ll MOD = 1000000007;
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int rgb2num(char c) {
	if (c == 'R') {
		return 0;
	}
	else if (c == 'G') {
		return 1;
	}
	else if (c == 'B') {
		return 2;
	}
	else {
		return -1;
	}
}
int main() {
	int n;
	string str;
	cin >> n;
	cin >> str;
	if (n < 4) {
		cout << 0 << endl;
		return 0;
	}
	vector<VE> vec(3,VE(n,0));
	vec[rgb2num(str[n - 1])][n-1] = 1;
	REP(i, n-1) {
		int rgbnum = rgb2num(str[n - 2-i]);
		REP(k, 3) {
			if (rgbnum == k) {
				vec[k][n - 2 - i] = vec[k][n - 1 - i] + 1;
			}
			else {
				vec[k][n - 2 - i] = vec[k][n - 1 - i];
			}
		}
	}
	ll ans = 0;
	REP(i, n-2) {
		for (int j = i + 1; j < n - 1; ++j) {
			if (str[j] == str[i]) {
				continue;
			}
			ans += vec[3 - rgb2num(str[i]) - rgb2num(str[j])][j+1];
			if (2 * j - i < n) {
				if (str[2 * j - i] != str[i] && str[2 * j - i] != str[j]) {
					ans--;
				}
			}
		}

	}
	cout << ans << endl;
	return 0;
}
