#include <iostream>
using namespace std;

int main(){
  long long int ans = 0;
  int n;
  int m;
  char color[4001];
  int r = 0, g = 0, b = 0;
  cin >> n;
  if(n < 3){
    cout << 0 << '\n';
    return 0;
  }
  for(int i=1; i<=n; i++){
    cin >> color[i];
    if(color[i] == 'R'){
      r += 1;
    }else if(color[i] == 'G'){
      g += 1;
    }else{
      b += 1;
    }
  }
  if(r*g*b == 0){
    cout << 0 << '\n';
    return 0;
  }
  for(int i=1; i<=n-2; i++){
    m = (i + n) / 2; 
    for(int j=1; j<=m; j++){
      if(color[i] != color[j] && color[j + j - i] != color[j] && color[i] != color[j + j - i]){
        ans += 1;
      }
    }
  }
  cout << r*g*b - ans << '\n';
  return 0;
}
