#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repd(a,b,c) for(int a=c;a>=b;a--)
/*******************************/
#define pi pair<int,int> 
#define vi vector<int>
#define vb vector<bool>
#define vp vector<pi>
#define vvi vector<vi>
#define vvp vector<vp>
/****************************/
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define pb push_back
//#define mp make_pair
#define pbb pop_back
/****************************************/
const int N = 5e5+100;
const int mod=1e9+7;
const int inf=1e18;
/****************************************/
vvp g;
vb vis;
vi dis,p,pp;
map<pair<pi,int>,int> mp;
int power(int a,int b)
{
  int ans=1;
  while(b)
  {
    if(b&1)ans*=a;
    a*=a;
    b/=2;
  }
  return ans;
}
// void dijkstra(int s,int n)
// {
//   dis.assign(n+1,inf);
//   p.assign(n+1,-1);
//   dis[s]=0;
//  // vis[s]=true;
//   priority_queue<pi,vp,greater<pi>> pq;
//   pq.push({dis[s],s});
//   while(!pq.empty())
//   {
//     int u = pq.top().S;
//     pq.pop();
//     if(vis[u])continue;
//     vis[u]=true;
//     int par=dis[u];
//     for(auto it:g[u])
//     {
//       int to = it.F;
//       int len = it.S;
//       if((mp[{{p[u],u},to}]))continue;
//       if(par+len<dis[to])
//       {
//         dis[to]=par+len;
//         p[to]=u;
//         pq.push({dis[to],to});
//       }
//     }
//   }

// }
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--)
    {
          int n;
          cin>>n;
          string s;
          cin>>s;
          int ans=0;
          int r[n]={0},g[n]={0},b[n]={0};
          for(int i=n-1;i>=0;i--)
          {
            if(i==n-1)
            {
              if(s[i]=='R')
              {
                r[i]=1;
              }
              else if(s[i]=='G')
              {
                g[i]=1;
              }
              else b[i]=1;
            }
            else
            {
              if(s[i]=='R')
              {
                r[i]=r[i+1]+ 1;
                b[i]=b[i+1];
                g[i]=g[i+1];
              }
              else if(s[i]=='G')
              {
                r[i]=r[i+1];
                b[i]=b[i+1];
                g[i]=g[i+1]+1;
              }
              else
              {
                r[i]=r[i+1];
                b[i]=b[i+1]+1;
                g[i]=g[i+1];
              } 
            }
          }
          // for(int i=0;i<n;i++)
          // {
          //   cout<<r[i]<<" "<<g[i]<<" "<<b[i]<<"\n";
          // }
            int sum=0;
            for(int i=1;i<n-1;i++)
            {
              for(int j=0;j<i;j++)
              {
                if(s[i]=='R')
                {
                  if(s[j]=='B')
                  {
                    sum+=g[i+1];
                    if(s[2*i-j]=='G')sum--;
                  }
                  else if(s[j]=='G')
                  {
                    sum+=b[i+1];
                    if(s[2*i-j]=='B')sum--;
                  }
                }
                else if(s[i]=='B')
                {
                  if(s[j]=='G')
                  {
                    sum+=r[i+1];
                    if(s[2*i-j]=='R')sum--;
                  }
                  else if(s[j]=='R')
                  {
                    sum+=g[i+1];
                    if(s[2*i-j]=='G')sum--;
                  }
                }
                else
                {
                  if(s[j]=='B')
                  {
                    sum+=r[i+1];
                    if(s[2*i-j]=='R')sum--;
                  }
                  else if(s[j]=='R')
                  {
                    sum+=b[i+1];
                    if(s[2*i-j]=='B')sum--;
                  }
                }
              }
            }
            
          
          cout<<sum<<"\n";




    }
  
    
    
               

                

     

        
        
      
      
      
    
    

    
    
}

Measured memory_bytes: 3676