#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>

char S[4010];
int R[4010];
int G[4010];
int B[4010];
int N;

void f(int *C, char c) {
  int sum = 0;
  C[0] = sum;
  for (int i = 0; i < N; ++i) {
    if (S[i] == c)
      ++sum;
    C[i+1] = sum;
  }
}

int main(void) {
  scanf("%d", &N);
  scanf("%s", &S[0]);

  f(R, 'R');
  f(G, 'G');
  f(B, 'B');
  // for (int i = 0; i <= N; ++i)
  //   printf("%d ", R[i]);

  uint64_t ans = 0;
  for (int i = 1; i < N - 1; ++i) {
    for (int l = 0; l < i; ++l) {
      if (S[i] == S[l])
        continue;
      char rc;
      if (S[i] == 'R')
        rc = S[l] == 'G' ? 'B' : 'G';
      else if (S[i] == 'G')
        rc = S[l] == 'R' ? 'B' : 'R';
      else
        rc = S[l] == 'G' ? 'R' : 'G';
      int *A;
      switch (rc) {
      case 'R': A = R; break;
      case 'G': A = G; break;
      case 'B': A = B; break;
      }
      int cnt = A[N] - A[i+1];
      int r = i * 2 - l;
      if (r < N && S[r] == rc)
        --cnt;
      ans += cnt;
    }
  }
  printf("%llu\n", ans);
}