#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	int n;
    string s;
  	cin>>n>>s;
  	int r=0,g=0,b=0;	
  	for(char ch : s){
    	if(ch == 'R') r++;
        else if(ch == 'G') g++;
        else b++;
  	}
  int ans = r*g*b;
  int rgb = 'R'-'A' + 'G'-'A' + 'B'-'A';
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int o = 2*j-i;
    	int x = s[i]-'A' + s[j]-'A' + s[o]-'A';
    	if(o < n && x == rgb) ans --;
    }
  }
  cout<<ans<<endl;
}