#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MAX=1e6;
const ll mod=1e9+7;
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
//#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define se second
#define fi first
#define pi acos(-1)
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define SIZE 5000 + 1

ll expo(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*expo((x*x)%M,(n-1)/2,M))%M;

}


void solve()
{
   string s;
   ll n;
   cin>>n;
   cin>>s;
   vector<ll> r(n,0),g(n,0),b(n,0);
   if(s[n-1]=='R')
    {
           r[n-1]=1;
       }
       else if(s[n-1]=='G')
       {
        g[n-1]=1;
        }
       else
       {
           b[n-1]=1;
       }
   for(int i=n-2;i>-1;i--)
   {
       if(s[i]=='R')
       {
           r[i]=r[i+1]+1;
           g[i]=g[i+1];
           b[i]=b[i+1];
       }
       else if(s[i]=='G')
       {
           r[i]=r[i+1];
           g[i]=g[i+1]+1;
           b[i]=b[i+1];
       }
       else
       {
           r[i]=r[i+1];
           g[i]=g[i+1];
           b[i]=b[i+1]+1;
       }
   }
  // for(int i=0;i<n;i++)cout<<b[i]<<" ";
   //out<<endl;
   ll ans=0;
  // debug3(r[n-1],g[n-1],b[n-1]);
   for(int i=0;i<(n-2);i++)
   {
       for(int j=i+1;j<(n-1);j++)
       {
          // debug4(i,j,s[i],s[j]);
         if(s[i]==s[j])continue;
         else if(s[i]=='R' && s[j]=='G')
         {
             ll temp=b[j+1];
            // debug2(temp,2*j-i);
             if((2*j-i)<n && s[2*j-i]=='B')
                temp--;
             ans+=temp;
         }
         else if(s[i]=='R' && s[j]=='B')
         {
             ll temp=g[j+1];
             if((2*j-i)<n && s[2*j-i]=='G')
                temp--;
             ans+=temp;
         }
         else if(s[i]=='G' && s[j]=='R')
         {
             ll temp=b[j+1];
             if((2*j-i)<n && s[2*j-i]=='B')
                temp--;
             ans+=temp;
         }
         else if(s[i]=='G' && s[j]=='B')
         {
             ll temp=r[j+1];
             if((2*j-i)<n && s[2*j-i]=='R')
                temp--;
             ans+=temp;
         }
         else if(s[i]=='B' && s[j]=='R')
         {
             ll temp=g[j+1];
             if((2*j-i)<n && s[2*j-i]=='G')
                temp--;
             ans+=temp;
         }
         else if(s[i]=='B' && s[j]=='G')
         {
             ll temp=r[j+1];
             if((2*j-i)<n && s[2*j-i]=='R')
                temp--;
             ans+=temp;
         }
       }
   }
   cout<<ans<<endl;
}

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


Measured memory_bytes: 3724