/*
  GOOD is not Enough
  You've got to be GREAT.
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios: :sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;


void solve()
{ 
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> r,g,b;
  f(i,n)
  {
      if(s[i]=='R')
        r.pb(i);
      else if(s[i]=='G')
        g.pb(i);
      else
        b.pb(i);
  }
  int cnt=0;
  f(i,r.size())
  {
      int pos;
      if(lower_bound(all(g),r[i])!=g.end())
        pos=lower_bound(all(g),r[i])-g.begin();
      else  
        break;
     fp(j,pos,g.size()-1)
     {
         int chk=2*g[j]-r[i];
         if(lower_bound(all(b),g[j])==b.end())
            break;
         int val=lower_bound(all(b),g[j])-b.begin();
         cnt+=(b.size()-val);
         if(binary_search(all(b),chk))
            cnt--;
     }
  }
  f(i,r.size())
  {
      int pos;
      if(lower_bound(all(b),r[i])!=b.end())
        pos=lower_bound(all(b),r[i])-b.begin();
      else  
        break;
     fp(j,pos,b.size()-1)
     {
         int chk=2*b[j]-r[i];
         if(lower_bound(all(g),b[j])==g.end())
            break;
         int val=lower_bound(all(g),b[j])-g.begin();
         cnt+=(g.size()-val);
         if(binary_search(all(g),chk))
            cnt--;
     }
  }
  f(i,b.size())
  {
      int pos;
      if(lower_bound(all(g),b[i])!=g.end())
        pos=lower_bound(all(g),b[i])-g.begin();
      else  
        break;
     fp(j,pos,g.size()-1)
     {
         int chk=2*g[j]-b[i];
         if(lower_bound(all(r),g[j])==r.end())
            break;
         int val=lower_bound(all(r),g[j])-r.begin();
         cnt+=(r.size()-val);
         if(binary_search(all(r),chk))
            cnt--;
     }
  }

  f(i,b.size())
  {
      int pos;
      if(lower_bound(all(r),b[i])!=r.end())
        pos=lower_bound(all(r),b[i])-r.begin();
      else  
        break;
     fp(j,pos,r.size()-1)
     {
         int chk=2*r[j]-b[i];
         if(lower_bound(all(g),r[j])==g.end())
            break;
         int val=lower_bound(all(g),r[j])-g.begin();
         cnt+=(g.size()-val);
         if(binary_search(all(g),chk))
            cnt--;
     }
  }
 
  
  f(i,g.size())
  {
      int pos;
      if(lower_bound(all(r),g[i])!=r.end())
        pos=lower_bound(all(r),g[i])-r.begin();
      else  
        break;
     fp(j,pos,r.size()-1)
     {
         int chk=2*r[j]-g[i];
         if(lower_bound(all(b),r[j])==b.end())
            break;
         int val=lower_bound(all(b),r[j])-b.begin();
         cnt+=(b.size()-val);
         if(binary_search(all(b),chk))
            cnt--;
     }
  }

  f(i,g.size())
  {
      int pos;
      if(lower_bound(all(b),g[i])!=b.end())
        pos=lower_bound(all(b),g[i])-b.begin();
      else  
        break;
     fp(j,pos,b.size()-1)
     {
         int chk=2*b[j]-g[i];
         if(lower_bound(all(r),b[j])==r.end())
            break;
         int val=lower_bound(all(r),b[j])-r.begin();
         cnt+=(r.size()-val);
         if(binary_search(all(r),chk))
            cnt--;
     }
  }

  cout << cnt << '\n';
 return;
}

signed main()
{
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
	}
  return 0;
}

Measured memory_bytes: 3696