#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
using namespace std;
using ll =long long;

int main() {
	string S;
	ll N;
	ll sum=0;
	
	map<ll,ll> R,G,B;
	
	cin >>N>> S;
	for (int i = 0; i < N; i++) {
		for (int j = i; j < N; j++) {
			if (S[j] == 'R') {
				R[i] ++;
			}
			if (S[j] == 'G') {
				G[i]++;
			}
			if (S[j] == 'B') {
				B[i]++;
			}
		}
	}
	for (int i = 0; i < N-2; i++) {
		for (int j = i + 1; j < N-1; j++) {
			if (S[i] != S[j]) {
				if (S[i] != 'R' && S[j] != 'R') {
					if (j + j - i< N && S[j - i + j] == 'R') {
						if (R[j + 1] - 1 > 0) {
							sum += R[j + 1] - 1;
						}
					}
					else {
						
							sum += R[j + 1];
						
					}
				}
				if (S[i] != 'G' && S[j] != 'G') {
					if (j + j - i <N && S[j - i + j] == 'G') {
						if (G[j + 1] - 1 > 0) {
							sum += G[j + 1] - 1;
						}
					}
					else {

						sum += G[j+1];
					}
				}
				if (S[i] != 'B' && S[j] != 'B') {
					if (j+j-i<N&&S[j - i + j] == 'B') {
						if (B[j + 1] - 1 > 0) {
							sum += B[j + 1] - 1;
						}
					}
					else {

						sum += B[j+1];
					}
				}
			}
		}
	}
	cout << sum;
	
	
}