#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	long long r = 0, g = 0, b = 0;
	for (int i = 0; i < n;i++) {
		if (s[i] == 'R') r++;
		else if (s[i] == 'G') g++;
		else b++;
	}
	long long  ans = r * g * b;
	for (int i = 0; i < n - 2;i++) {
		for (int j = 1; j < n / 2;j++) {
			if (i + 2 * j < n && s[i] != s[i + j] && s[i] != s[i + 2 * j] && s[i + j] != s[i + 2 * j]) ans--;
		}
	}
	cout << ans << endl;
}
