#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end() 
#define MOD 1000000007
#define N 100005
#define pll pair<ll,ll>
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));


void solve()
{ 
     ll n;
     cin >> n;
     string s;
     cin >> s;
     s = 'a' + s;
     ll pre[n+2][3];
     memset(pre,0,sizeof(pre));
     for(ll i=1;i<=n;i++)
     {
          if(s[i]=='R')     pre[i][0]++;
          if(s[i]=='G')     pre[i][1]++;
          if(s[i]=='B')     pre[i][2]++;
     }
     for(ll i=n-1;i>=0;i--) 
     {
          pre[i][0] += pre[i+1][0];
          pre[i][1] += pre[i+1][1];
          pre[i][2] += pre[i+1][2];
     }
     ll ans = 0;
     for(ll i=1;i<=n;i++)
     {
          for(ll j=i+1;j<=n;j++)
          {
               if(s[i]!=s[j])
               {
                    char c = 'R' + 'G' + 'B' - s[i] - s[j];
                    ll id;
                    if(c=='R')   id = 0;
                    if(c=='G')   id = 1;
                    if(c=='B')   id = 2;
                    ans += pre[j+1][id];
                    ll dif = j - i;
                    ll newi = j + dif;
                    if(newi<=n && s[newi]==c)   ans--;
               }
          }
     }
     cout<<ans;
}

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