//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr <<  #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }


void solve()
{ 
  int n;
  cin>>n;
  string s;
  cin>>s;
  int dp[n][3];
   if(s[0]=='R')
       dp[0][0]=1;
   else if(s[0]=='G')
        dp[0][1]=1;
    else
        dp[0][2]=1;

  rep(i,1,n)
    {  
       dp[i][0]=dp[i-1][0];
       dp[i][1]=dp[i-1][1];
       dp[i][2]=dp[i-1][2];
       if(s[i]=='R')
       dp[i][0]+=1;
   else if(s[i]=='G')
        dp[i][1]+=1;
    else
        dp[i][2]+=1;






    }


    vec<pair<int,int> > v;
    for(int i=0;i<n;i++)
          {
            for(int j=i+1;j<n;j++)
                  {
                    if(s[j]!=s[i])
                          v.pb({i,j});

                  }
          }

          int ans=0;
          for(auto i:v)
              {
                 if(s[i.F]=='R' and s[i.S]=='G')
                      {
                        ans+=dp[n-1][2]-dp[i.S][2];
                          if(i.S+i.S-i.F<n and s[i.S+i.S-i.F]=='B')
                              ans--;

                      }
                      if(s[i.F]=='R' and s[i.S]=='B')
                      {
                        ans+=dp[n-1][1]-dp[i.S][1];
                          if(i.S+i.S-i.F<n and s[i.S+i.S-i.F]=='G')
                              ans--;

                      }
                      if(s[i.F]=='B' and s[i.S]=='G')
                      {
                        ans+=dp[n-1][0]-dp[i.S][0];
                          if(i.S+i.S-i.F<n and s[i.S+i.S-i.F]=='R')
                              ans--;

                      }
                      if(s[i.F]=='B' and s[i.S]=='R')
                      {
                        ans+=dp[n-1][1]-dp[i.S][1];
                          if(i.S+i.S-i.F<n and s[i.S+i.S-i.F]=='G')
                              ans--;

                      }
                      if(s[i.F]=='G' and s[i.S]=='R')
                      {
                        ans+=dp[n-1][2]-dp[i.S][2];
                          if(i.S+i.S-i.F<n and s[i.S+i.S-i.F]=='B')
                              ans--;

                      }
                      if(s[i.F]=='G' and s[i.S]=='B')
                      {
                        ans+=dp[n-1][0]-dp[i.S][0];
                          if(i.S+i.S-i.F<n and s[i.S+i.S-i.F]=='R')
                              ans--;

                      }










              }
              cout<<ans;

}
signed main()
{fast
    int t;
  t=1;
   //cin>>t;
  while(t--)
     {
      solve();
     }



}
  













Measured memory_bytes: 134524