#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
using ll = long long;
using P = pair<ll,ll>;

int main (){
  int n;cin>>n;
  string s;cin>>s;
  ll numR=0,numG = 0,numB = 0;
  rep(i,n){
    if (s.at(i) == 'R'){
      numR++;
    }
    else if (s.at(i) == 'G'){
      numG++;
    }
    else if (s.at(i) =='B'){
      numB ++;
    }
  }
  ll sum = 0;
  rep(i,n){
    for (int j = 1;j<=(n-i-1)/2;j++){
      if (s.at(i) != s.at(i+j) && s.at(i) != s.at(i + 2*j) && s.at(i+j) != s.at(i+2*j)){
        sum++;
      }
    }
  }
  cout << numR*numG*numB - sum << endl;
}