#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
constexpr double eps = 1e-6;
constexpr ll LINF = 100200300400500600ll;
constexpr int INF = 2*((1<<30)-1)+1;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {-1,0,1,0};
constexpr int mod = 1000000007;
#define Yes(ifeq) cout<<(( ifeq )? "Yes":"No")<<endl;

void Main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  vi r(n,0),g(n,0),b(n,0);
    r[n-1] = (s[n-1]=='R');
    g[n-1] = (s[n-1]=='G');
    b[n-1] = (s[n-1]=='B');
  drep(i,n){
    if(i!=0){
      r[i-1] = r[i] + (s[i-1]=='R');
      g[i-1] = g[i] + (s[i-1]=='G');
      b[i-1] = b[i] + (s[i-1]=='B');
    }
  }
  ll sum=0;
  rep(i,n-2){
    if(s[i] =='R'){
      srep(j,i+1,n){
        if(s[j] == 'G'){
          int p = b[j];
          int k = j-i;
          if(j+k<n){
            if(s[j+k]=='B') p--; 
          }
          sum+=max(p,0);
        } else if( s[j] == 'B' ){
          int p = g[j];
          int k = j-i;
          if(j+k<n){
            if(s[j+k]=='G') p--; 
          }
          sum+=max(p,0);
        }
      }
    }else if(s[i]=='G') {
      srep(j,i+1,n){
        if(s[j] == 'R'){
          int p = b[j];
          int k = j-i;
          if(j+k<n){
            if(s[j+k]=='B') p--; 
          }
          sum+=max(p,0);
        } else if( s[j] == 'B' ){
          int p = r[j];
          int k = j-i;
          if(j+k<n){
            if(s[j+k]=='R') p--; 
          }
          sum+=max(p,0);
        }
      }      
    } else {
      srep(j,i+1,n){
        if(s[j] == 'R'){
          int p = g[j];
          int k = j-i;
          if(j+k<n){
            if(s[j+k]=='G') p--; 
          }
          sum+=max(p,0);
        } else if( s[j] == 'G' ){
          int p = r[j];
          int k = j-i;
          if(j+k<n){
            if(s[j+k]=='R') p--; 
          }
          sum+=max(p,0);
        }
      }      
    }
  }
  cout<<sum<<endl;

} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 3664