#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;

int N;
string S;
int sn[4000];

int main()
{
  int i,j,k;
  int rn=0,gn=0,bn=0;
  int d;
  int l;
  int t;
  long sum=0;

  cin >> N;
  cin >> S;

  for (i=0; i<N; i++) {
    switch(S[i]) {
    case 'R': rn++; sn[i] = 1; break;
    case 'G': gn++; sn[i] = 2; break;
    case 'B': bn++; sn[i] = 4; break;
    }
  }


  for (i=0; i<N-2; i++) {
    for (j=i+1; j+j-i<N; j++) {
      if ((sn[i]|sn[j]|sn[j+j-i])==7) sum++;
    }
  }

  printf("%ld\n", rn*gn*bn-sum);

  return 0;
}
