#include <stdio.h>

int main(void)
{

  long long int n;
  char s[4000];

  long long int count_R=0, count_G=0, count_B=0;
  long long int ans=0, not_ans=0;
  long long int i, j;

  scanf("%lld", &n);
  scanf("%s", s);

  for (i=0;i<n;i++) {
    switch (s[i]) {
    case 'R': count_R++; break;
    case 'G': count_G++; break;
    case 'B': count_B++; break;
    }
  }

  ans = count_R*count_G*count_B;

  for (i=0;i<n;i++) {
    for (j=1;j<=(n-1-i)/2;j++) {
      if (s[i]!=s[i+j] && s[i+j]!=s[i+j+j] && s[i+j+j]!=s[i])
	not_ans++;
    }
  }

  ans -= not_ans;

  printf("%lld", ans);

  return 0;
}
