//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
int foo(string s,char ch1,char ch2,char ch3){
	int ans = 0;
	vector<int> suf(n);
	if(s[n-1] == ch3){
		suf[n-1] = 1;
	}
	for(int i=n-2;i>=0;i--){
		if(s[i] == ch3){
			suf[i] = 1;
		}
		suf[i] += suf[i+1];
	}
	for(int i=0;i<n;i++){
		if(s[i] == ch1){
			for(int j=i+1;j<n;j++){
				if(s[j] == ch2){
					ans += suf[j];
					if((2*j - i) < n){
						if(s[2*j - i] == ch3) ans--;
					}
				}
			}
		}
	}
	return ans;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	string s;
	cin >> s;
	vector<char> ch;
	ch.push_back('B');
	ch.push_back('G');
	ch.push_back('R');
	int ans = 0;
	do{
		ans += foo(s,ch[0],ch[1],ch[2]);
	}while(next_permutation(all(ch)));
	cout<<ans;
}
//.........