#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define dl double long
const int INF=0x3fffffff;
const ll MOD=1000000007;
const ll MODD=998244353;
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

int main()
{
  ll N, R=0, G=0, B=0, mm=0;
  string S;
  cin >> N >> S;

  rep(i, N){
    if(S[i] == 'R') ++R;
    if(S[i] == 'G') ++G;
    if(S[i] == 'B') ++B;
  }

  for(ll i=1; 3+2*(i-1) < N; ++i){
    for(ll j=0; j+2*i < N; ++j){
      if(S[j+0*i] != S[j+1*i] && S[j+0*i] != S[j+2*i] && S[j+1*i] != S[j+2*i]){
            ++mm;
      }
    }
  }

  cout << max((ll)0, R*G*B-mm) << "\n";
}