#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[4002];
int c1[3];
int c2[3];
int dis(char a, char b, char c){
  if(a==b || a==c || b==c){
    return 0;
  }
  return 1;
}
int main(){
  int i;
  int j;
  int k;
  int len;
  long long res = 0;
  rd(N);
  rd(S);
  for(i=(0);i<(N);i++){
    if(S[i]=='R'){
      S[i] =0;
    }
    else if(S[i]=='G'){
      S[i] =1;
    }
    else{
      S[i] =2;
    }
  }
  for(i=(0);i<(N);i++){
    for(k=(0);k<(3);k++){
      c1[k] = c2[k] = 0;
    }
    for(j=(0);j<(i);j++){
      c1[S[j]]++;
    }
    for(j=(i+1);j<(N);j++){
      c2[S[j]]++;
    }
    len =min_L(i, N-i-1);
    for(j=(1);j<(len+1);j++){
      res -= dis(S[i-j], S[i], S[i+j]);
    }
    for(j=(0);j<(3);j++){
      for(k=(0);k<(3);k++){
        if(dis(S[i],j,k)){
          res += c1[j] * c2[k];
        }
      }
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200412-1

// --- original code ---
// int N;
// char S[4002];
// int c1[3], c2[3];
// 
// int dis(char a, char b, char c){
//   if(a==b || a==c || b==c) return 0;
//   return 1;
// }
// 
// {
//   int i, j, k, len;
//   ll res = 0;
//   rd(N,S);
//   rep(i,N) S[i] = if[S[i]=='R', 0, S[i]=='G', 1, 2];
//   rep(i,N){
//     rep(k,3) c1[k] = c2[k] = 0;
//     rep(j,i) c1[S[j]]++;
//     rep(j,i+1,N) c2[S[j]]++;
//     len = min(i, N-i-1);
//     rep(j,1,len+1) res -= dis(S[i-j], S[i], S[i+j]);
//     rep(j,3) rep(k,3) if(dis(S[i],j,k)) res += c1[j] * c2[k];
//   }
//   wt(res);
// }


Measured memory_bytes: 3644