/*input
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB
*/
/*
       _==/          i     i          \==_
     /XX/            |\___/|            \XX\
   /XXXX\            |XXXXX|            /XXXX\
  |XXXXXX\_         _XXXXXXX_         _/XXXXXX|
 XXXXXXXXXXXxxxxxxxXXXXXXXXXXXxxxxxxxXXXXXXXXXXX
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX|
 XXXXXX/^^^^'\XXXXXXXXXXXXXXXXXXXXX/^^^^^\XXXXXX
  |XXX|       \XXX/^^\XXXXX/^^\XXX/       |XXX|
    \XX\       \X/    \XXX/    \X/       /XX/
       '\       '      \X/      '      /'

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//loops
#define f(i,s,n) for(ll i=(ll)s;i<(ll)n;i++)
#define rf(i,n,s) for(ll i=(ll)(n-1);i>=(ll)s;i--)
//reset
#define ms0(X) memset((X), 0, sizeof((X)))
#define ms1(X) memset((X), -1, sizeof((X)))
//IO
#define bio ios_base::sync_with_stdio;cin.tie(NULL)
//STL
#define pb push_back
#define pii pair<ll,ll>
#define vll vector<ll>
#define vpii vector<pii >
#define mll map<ll, ll>
#define mpii map<pii,ll> 
#define msll map<string, ll> 
#define sortv(v) sort(v.begin(),v.end())
#define F first
#define S second
//standard values
#define mod (ll)(1e9+7)
#define INF (ll)1e16
#define MAXN (ll)(1e5+5)
//comparator
bool cmp(pii a, pii b)
{
    return a.F < b.F;
}
ll exp(ll a,ll b){ll ans=1;while(b!=0){if(b%2==1)ans=ans*a;a=a*a;b/=2;}return ans;}
/********************************************************************************************************/
ll fnc(ll a, ll b) {
  if (b == 0)
  {
    return a;
  }
  return fnc(b, a%b);
}
ll gcd(ll a, ll b, ll c) {
  return fnc(fnc(a,b),c);
}
ll r[4005], g[4005], b[4005];
int main() 
{
  bio;
  ll n;
  string s;
  cin>>n>>s;
  s = '*' + s;
  f(i,1,s.size()) {
    if(s[i] == 'R') {
      r[i] = r[i-1] + 1;
      g[i] = g[i-1];
      b[i] = b[i-1];
    } else if(s[i] == 'G') {
      r[i] = r[i-1];
      g[i] = g[i-1] + 1;
      b[i] = b[i-1];
    } else {
      r[i] = r[i-1];
      g[i] = g[i-1];
      b[i] = b[i-1] + 1;
    }
  }
  ll ans = 0;
  f(i, 1, s.size()) {
    f(j, i+1, s.size()) {
      if (s[i] != s[j]) {
        //cout<<"i: "<<i<<" j:"<<j<<" ans:"<<ans<<endl;
        if(s[i] == 'R' && s[j] == 'B') {
          ans += g[j] - g[i-1];
          if((j-i)%2 == 0 && s[(j-i)/2+i] == 'G') {
            ans--;
          } 
        }
        //cout<<ans<<endl;
        if(s[i] == 'R' && s[j] == 'G') {
          ans += b[j] - b[i-1];
          if((j-i)%2 == 0 && s[(j-i)/2+i] == 'B') {
            ans--;
          }
        }
        //cout<<ans<<endl;
        if(s[i] == 'G' && s[j] == 'B') {
          ans += r[j] - r[i-1];
          if((j-i)%2 == 0 && s[(j-i)/2+i] == 'R') {
            ans--;
          }
        }
        //cout<<ans<<endl;
        if(s[i] == 'G' && s[j] == 'R') {
          ans += b[j] - b[i-1];
          if((j-i)%2 == 0 && s[(j-i)/2+i] == 'B') {
            ans--;
          }
        }
        //cout<<ans<<endl;
        if(s[i] == 'B' && s[j] == 'G') {
          ans += r[j] - r[i-1];
          if((j-i)%2 == 0 && s[(j-i)/2+i] == 'R') {
            ans--;
          }
        }
        //cout<<ans<<endl;
        if(s[i] == 'B' && s[j] == 'R') {
          ans += g[j] - g[i-1];
          if((j-i)%2 == 0 && s[(j-i)/2+i] == 'G') {
            ans--;
          }
        }
        //cout<<s[i]<<" "<<s[j]<<" "<<ans<<endl;
      }
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 3708