#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace std;
    using namespace __gnu_pbds; 
    #define lli long long int
    #define fr(i,a,b) for(lli i=a;i<b;i++)
    #define bfr(i,a,b) for(lli i=a;i>=b;i--)
    #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
    #define tc int t;cin>>t;while(t--)
    #define mod 1000000007LL
    #define mod2 998244353LL
    #define all(vec) vec.begin(),vec.end()  
    #define ld long double
    #define pb push_back

    #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 



    int main()
    {
                           
             

            
                        
              fio

              lli n,sum=0;
              string s;
              cin>>n>>s;

              fr(i,0,n-2)
              {
             
                 if(s[i]=='R')
                   {   lli g[n]={0},b[n]={0},cntb=0,cntg=0;
                      fr(j,i+1,n)
                      {
                          if(s[j]=='B')
                          {
                              b[j]=1;cntb++;
                              
                              sum+=cntg;
                                 if((j+i)%2==0 && g[(j+i)/2]==1)sum--;
                                
                          }
                          else if(s[j]=='G')
                          {
                                 g[j]=1;
                                 cntg++;
                                 sum+=cntb;
                                 if((j+i)%2==0 && b[(j+i)/2]==1)sum--;
                          }

                      }

                   }
                   if(s[i]=='G')
                   {   lli g[n]={0},b[n]={0},cntb=0,cntg=0;
                      fr(j,i+1,n)
                      {
                          if(s[j]=='B')
                          {
                              b[j]=1;cntb++;
                              sum+=cntg;
                                 if((j+i)%2==0 && g[(j+i)/2]==1)sum--;
                          }
                          else if(s[j]=='R')
                          {
                                 g[j]++;
                                 cntg++;
                                 sum+=cntb;
                                 if((j+i)%2==0 && b[(j+i)/2]==1)sum--;
                          }
                      }

                   }

                    if(s[i]=='B')
                   {   lli g[n]={0},b[n]={0},cntb=0,cntg=0;
                      fr(j,i+1,n)
                      {
                          if(s[j]=='R')
                          {
                              b[j]=1;cntb++;
                              sum+=cntg;
                                 if((j+i)%2==0 && g[(j+i)/2]==1)sum--;
                          }
                          else if(s[j]=='G')
                          {
                                 g[j]++;
                                 cntg++;
                                 sum+=cntb;
                                 if((j+i)%2==0 && b[(j+i)/2]==1)sum--;
                          }
                      }
                   }

                 
                   

              }

              cout<<sum<<'\n';
return 0;}

Measured memory_bytes: 3700