#include <stdio.h>
#include <iostream>
#include <string>

#define MAX_N 4010

int main() {
  int n;
  std::string s;
  scanf("%d", &n);
  std::cin >> s;
  int leftR[MAX_N], rightR[MAX_N];
  int leftG[MAX_N], rightG[MAX_N];
  int leftB[MAX_N], rightB[MAX_N];
  leftR[0] = 0;
  leftG[0] = 0;
  leftB[0] = 0;
  rightR[n-1] = 0;
  rightG[n - 1] = 0;
  rightB[n - 1] = 0;
  for (int i = 0; i < n-1; i++) {
    leftR[i+1] = leftR[i] + (s[i] == 'R');
    leftG[i + 1] = leftG[i] + (s[i] == 'G');
    leftB[i + 1] = leftB[i] + (s[i] == 'B');
  }
  for (int k = n-1; k >= 1; k--) {
    rightR[k-1] = rightR[k] + (s[k] == 'R');
    rightG[k - 1] = rightG[k] + (s[k] == 'G');
    rightB[k - 1] = rightB[k] + (s[k] == 'B');
  }
  long long ans = 0;
  for (int j = 1; j < n-1; j++) {
    if (s[j] == 'R') {
      ans += leftG[j] * rightB[j];
      ans += leftB[j] * rightG[j];
      for (int i = 0; i < j; i++) {
        if (s[i] == 'G' && 2*j-i < n && s[2*j-i] == 'B') ans--;
        if (s[i] == 'B' && 2 * j - i < n && s[2 * j - i] == 'G')
          ans--;
      }
    }
    if (s[j] == 'G') {
      ans += leftR[j] * rightB[j];
      ans += leftB[j] * rightR[j];
      for (int i = 0; i < j; i++) {
        if (s[i] == 'R' && 2 * j - i < n && s[2 * j - i] == 'B')
          ans--;
        if (s[i] == 'B' && 2 * j - i < n && s[2 * j - i] == 'R')
          ans--;
      }
    }
    if (s[j] == 'B') {
      ans += leftG[j] * rightR[j];
      ans += leftR[j] * rightG[j];
      for (int i = 0; i < j; i++) {
        if (s[i] == 'G' && 2 * j - i < n && s[2 * j - i] == 'R')
          ans--;
        if (s[i] == 'R' && 2 * j - i < n && s[2 * j - i] == 'G')
          ans--;
      }
    }
  }

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

  return 0;
}
