#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>	
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
ll a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;

int main()
{
	cin >> n >> s;
	vector<int> R, G, B;
	rep(i, n) {
		if (s[i] == 'R')R.push_back(i);
		else if (s[i] == 'G')G.push_back(i);
		else B.push_back(i);
	}
	int sum = 0;
	for (int i = 1; i <(n-3)/2+2 ; i++) {
		rep(j, n - 2 * i) {
			if (s[j] != s[j + i] && s[j + i * 2] != s[j] && s[j + i] != s[j + i * 2])
				sum++;
		}
	}
	cout << R.size() * G.size() * B.size() - sum << endl;	

	return 0;
}
