#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,tmp;
  ll rCount=0,gCount=0,bCount=0;
  char s[LIMIT1];
  ll dMin,dist;
  
  scanf("%lld",&n);
  scanf("%s",s);
  
  rep(i,n){
    switch(s[i]){
      case 'R':
        rCount++;
        break;
      case 'G':
        gCount++;
        break;
      case 'B':
        bCount++;
        break;
    }
  }
  
  result = rCount*gCount*bCount;
  for(dist=1;dist<=n/2;dist++){
    for(i=0;i<n-dist;i++){
      j=i+dist;
      k=i+2*dist;
      if(k>=n) break;
      
      if(s[i]==s[j]) continue;
      else if(s[i]==s[k]) continue;
      else if(s[j]==s[k]) continue;
      result--;
    }
  }
  
  printf("%lld",result);
  return 0;
}

