#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> a(3);
  rep(i,N){
    if(S[i] == 'R') a[0]++;
    if(S[i] == 'G') a[1]++;
    if(S[i] == 'B') a[2]++;
  }
  ll ans = a[0]*a[1]*a[2];
  rep(i,N){
    for(int j = 1+i;j<N;j++){
    int k = 2*j - i;
    if(k<N){
      if(S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) --ans;
    }
  }
}
    cout << ans << endl;
}
