#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N; string S;
  cin >> N; cin >> S;
  
  ll red=0, green=0, blue=0;
  for(int i=0; i<N; i++){
    if(S[i]=='R'){
      red ++; 
    }else if(S[i]=='G'){
      green ++; 
    }else{
      blue ++; 
    }
  }
  
  //main
  ll ans = red*green*blue;
  //cout << ans << endl;
  for(int i=0; i<N; i++){
    if(S[i]=='G'){
      for(int j=0; j<N; j++){
        if(S[j]=='B'){
          if(i>j){
            if((i-j-1)%2==1 && S[(i+j)/2]=='R'){
              ans -= 1; 
            }
            if(0<=2*j-i && 2*j-i<=N-1 && S[2*j-i]=='R'){
              ans -= 1; 
            }
            if(0<=2*i-j && 2*i-j<=N-1 && S[2*i-j]=='R'){
              ans -= 1;
            }
          }else if(i<j){
            if((j-i-1)%2==1 && S[(i+j)/2]=='R'){
              ans -= 1; 
            }
            if(0<=2*i-j && 2*i-j<=N-1 && S[2*i-j]=='R'){
              ans -= 1; 
            }
            if(0<=2*j-i && 2*j-i<=N-1 && S[2*j-i]=='R'){
              ans -= 1;
            }
          }
        }
      }
    }
  }
  
  // output
  cout << ans << endl;

  return 0;
}