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

int main(void) {
  int n;
  scanf("%d", &n);
  char str[n + 2];
  memset(str, '\0', n);
  scanf(" %s", str);

  long long int sum = 0;
  int r_ptr = 0, g_ptr = 0, b_ptr = 0;
  for (int i = 0; i < n; i++) {
    if (str[i] == 'R') {
      r_ptr++;
    } else if (str[i] == 'G') {
      g_ptr++;
    } else if (str[i] == 'B') {
      b_ptr++;
    }
  }

  for (int i = 1; i <= (n / 2); i++) {
    int x = 0, y = x + i, z = x + 2 * i;
    for (int j = 0; j < (n - z); j++) {
      if ((str[x + j] != str[y + j]) && (str[y + j] != str[z + j]) && (str[x + j] != str[z + j])) sum++;
    }
  }

  printf("%lld\n", (long long int) r_ptr * (long long int) g_ptr * (long long int) b_ptr - sum);

  return 0;
}
