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

int rgb[3][4005];

int main(){
  int n;
  string s;
  cin>>n>>s;
  rep(i,n){
    rep(j,3) rgb[j][i+1]+=rgb[j][i];
    if(s[i]=='R') rgb[0][i+1]++;
    else if(s[i]=='G') rgb[1][i+1]++;
    else rgb[2][i+1]++;
  }
  ll ans=0;
  string t="RGB";
  rep(i,n) rep(j,i){
    if(s[i]==t[0]&&s[j]==t[1]){
      int k=2*j-i;
      ans+=rgb[2][j];
      if(k>=0&&s[k]==t[2]) ans--;
    }
    if(s[i]==t[0]&&s[j]==t[2]){
      int k=2*j-i;
      ans+=rgb[1][j];
      if(k>=0&&s[k]==t[1]) ans--;
    }
    if(s[i]==t[1]&&s[j]==t[2]){
      int k=2*j-i;
      ans+=rgb[0][j];
      if(k>=0&&s[k]==t[0]) ans--;
    }
    if(s[i]==t[1]&&s[j]==t[0]){
      int k=2*j-i;
      ans+=rgb[2][j];
      if(k>=0&&s[k]==t[2]) ans--;
    }
    if(s[i]==t[2]&&s[j]==t[0]){
      int k=2*j-i;
      ans+=rgb[1][j];
      if(k>=0&&s[k]==t[1]) ans--;
    }
    if(s[i]==t[2]&&s[j]==t[1]){
      int k=2*j-i;
      ans+=rgb[0][j];
      if(k>=0&&s[k]==t[0]) ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}