#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
int A[4005]={0};

int main(){
  int n;
  ll rn=0;
  ll gn=0;
  ll bn=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    char c;
    cin>>c;
    if(c=='R'){rn++;A[i]=1;}
    else if(c=='G'){gn++;A[i]=2;}
    else{bn++;A[i]=3;}
  }
  ll ans=rn*gn*bn;
  for(int i=1;1+2*i<=n;i++){
    for(int j=1;j+2*i<=n;j++){
      if(A[j]!=A[j+i]&&A[j+i]!=A[j+2*i]&&A[j]!=A[j+2*i])ans--;
    }
  }
  cout<<ans<<endl;
}
