#include <stdio.h>

int main(void) {
  int n;
  scanf("%d", &n);

  char s[4010];
  scanf("%s", s);

  long long int r, g, b;
  r = g = b = 0;
  for (int i = 0; i < n; i++) {
    switch (s[i]) {
    case 'R':
      r++;
      break;
    case 'G':
      g++;
      break;
    case 'B':
      b++;
      break;
    }
  }

  long long int ans = r * g * b;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int k = 2 * j - i;
      if (k >= n) continue;
      ans -= (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]);
    }
  }

  printf("%lld\n", ans);

  return 0;
}
