#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

//0 R 1 : G 2 : B
ll dp[3][4000];

int RGB2INT(char c){
    if (c == 'R') return 0;
    if(c == 'G') return 1;
    return 2;
}

int main(){
  ll N;
  ll sum=0;
  int ni, nj, nk, k;
  char S[5000];
  char RGB[3] = {'R', 'G', 'B'};
  
  scanf("%lld", &N);
  scanf("%s", S);
  
  dp[RGB2INT(S[N-1])][N-1]++;

  for (int i = N-2; i >= 0; i--)
  {
      dp[0][i] = dp[0][i+1];
      dp[1][i] = dp[1][i+1];
      dp[2][i] = dp[2][i+1];

      dp[RGB2INT(S[i])][i]++;
  }

  for (int i = 0; i < N; i++)
  {
      for (int j = i+1; j < N; j++)
      {
          if(S[i] == S[j]) continue;

          ni = RGB2INT(S[i]);
          nj = RGB2INT(S[j]);
          nk = 3 - ni -nj;

          sum += dp[nk][j];

          k = 2*j -i;
          if(k < N && S[k] == RGB[nk]) sum--;

      }
  }
  
  printf("%lld", sum);
  
  
  return 0;
}