#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

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

using namespace std;

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   if(n<3)
   {
       cout<<0;
       return 0;
   }
   ll ans = 0;
   for(ll i=0;i<n-2;i++)
   {
       map<char,ll> ma;
       ma[s[i+1]]++;
       for(ll j=i+2;j<n;j++)
       {
           if(s[i] == s[j])
           {
               ma[s[j]]++;
               continue;
           }
           ll cnt = 0;
           unordered_map<char,ll> ma1;
           ma1[s[i]]++;
           ma1[s[j]]++;
           char ch;
           if(ma1['R'] == 0)
                cnt = ma['R'], ch = 'R';
           else if(ma1['B'] == 0)
                cnt = ma['B'], ch = 'B';
           else cnt = ma['G'], ch = 'G';
           if((j+i)%2 == 0 && s[(j+i)/2] == ch)
                cnt--;        
           ans+=cnt;
           ma[s[j]]++;
       }
   }
   cout<<ans;
   
   return 0;        
}  
   