#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main(){
	int n;
	string s;
	int rc(0), gc(0), bc(0);
	cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'R')++rc;
		if (s[i] == 'G')++gc;
		if (s[i] == 'B')++bc;
	}

	ll count;
	count = rc * gc * bc;
	rep(i, n) {
		for (int j = i + 1; j < n; ++j) {
			if (2*j - i < n) {
				if (s[i]!=s[j] &&s[j]!=s[2*j-i] && s[i]!=s[2*j-i]){				
						count--;
				}
			}

		}
	}
	cout << count;
	return 0;
}