#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000001;

int main(){
  int N;
  cin >> N;
  vector<ll> R, G, B;
  rep(i,N){
    char a;
    cin >> a;
    if(a == 'R') R.push_back(i+1);
    if(a == 'G') G.push_back(i+1);
    if(a == 'B') B.push_back(i+1);
  }
  ll ans = R.size() * G.size() * B.size();
  for(ll i:R){
    for(ll j:G){
      ll a = 0, b = 0, c = 0;
      ll s = 2*i-j, t = 2*j-i;
      if((i+j)%2 == 0){
        a = (i+j)/2;
      }
      if(s <= N){
        b = s;
      }
      if(t <= N){
        c = t;
      }
      for(ll k:B){
        if(a == k || b == k || c == k){
          ans--;
        }
      }
    }
  }
  cout << ans <<endl;
}