#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main()
{
  int N;
  string S;
  cin >> N >> S;
  int r=0,g=0,b=0;
  rep(i,N){
    char c = S.at(i);
    if(c=='R'){
      r++;
    }else if(c=='G'){
      g++;
    }else{
      b++;
    }
  }
  ll num = r * g * b;
  rep(i,N){
    for(int j=i+1;j<N;j++){
      int k = 2 * j - i;
      if(k<0||N<=k||k<=j)
        continue;
      if(S.at(i)!=S.at(j)&&S.at(j)!=S.at(k)&&S.at(k)!=S.at(i)){
        num--;
      }else{

      }
    }
  }
  cout << num << endl;
}