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

void sort(int a, int b, int c, int *x, int *y, int *z) {
  int num[] = {a, b, c};
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      if (num[j] > num[j + 1]) {
        int tmp = num[j];
        num[j] = num[j + 1];
        num[j + 1] = tmp;
      }
    }
  }

  *x = num[0]; *y = num[1]; *z = num[2];
}

int main(void) {
  int n;
  scanf("%d", &n);
  char str[n + 1];
  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 = z; j < n; j++) {
      if (str[x] != str[y] && str[y] != str[z] && str[x] != str[z]) sum++;
      x++; y++; z++;
    }
  }

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

  return 0;
}
