#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;
/*
ordered_set(both these operations in log)
1. find_by_order : it returns iterator to the ith largest element.
2. order_of_key  : The number of items in a set that are strictly smaller than k.
*/

//memset(dp,-1,sizeof(dp));
//fill(v.begin(), v.end(), -1);
//priority_queue< pii, vector <pii> , greater<pii>> pq;
//vector<int> dist(V, INF);


#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define lb lower_bound
#define ub upper_bound

#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define pii                 pair<int,int>
#define vi                  vector<int>
#define vii                 vector<pii>
#define mi                  map<int,int>
#define mii                 map<pii,int>
#define all(a)              (a).begin(),(a).end()
#define fi                  first
#define se                  second
#define sz(x)               (int)x.size()
#define endl                '\n'
#define md                  1000000007
#define rep(i,a,b)          for(int i=a;i<b;i++)
#define pcout(x)	          cout<<fixed<<setprecision(x)
#define debug(x)            cout<<#x<<"::"<<x<<endl;
#define debug2(x,y)         cout<<#x<<"::"<<x<<"\t"<<#y<<"::"<<y<<endl;
#define boost               ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)



typedef long long ll;
typedef double ld;

inline ll prodm(ll a,ll b)  {return ((a%md)*(b%md))%md;}
inline ll summ(ll a,ll b)   {return ((a%md)+(b%md))%md;}
inline bool ispow2(ll x)    {return  x && (!(x&(x-1)));}

const int N = 1e5 + 5;
const ll  infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;

/**************************BounceBackBolt*********************************/
ll fastexpo(ll n,ll pwr)
{
  if(pwr==0)
    return 1;
  if(pwr==1)
    return n;
  ll ans=fastexpo(n,pwr/2);
  ans=prodm(ans,ans);
  if(pwr&1)
  {
      ans=prodm(ans,n);
  }
    return ans;
}

ll modInverse(ll base)
{return fastexpo(base,md-2);}


vector < int > g[N];
int d[N];
void dfs(int v, int p, int dd){
    d[v] = dd;
    for(int to : g[v]){
        if(to == p) continue;
        dfs(to, v, dd + 1);
    }
}

/*********************************************************************/
int main()
{
  boost;
  int T;
  T=1;
  while(T--)
  {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int dp[3][n+1];
    memset(dp,0,sizeof(dp));
    int i=n-1;
    while(i>=0)
    {
      dp[0][i]=dp[0][i+1];
      dp[1][i]=dp[1][i+1];
      dp[2][i]=dp[2][i+1];

      if(s[i]=='R')
      dp[0][i]++;
      else if(s[i]=='B')
      dp[1][i]++;
      else
      dp[2][i]++;
      i--;
    }

    ll ans=0;
    /*for(int i=0;i<3;i++)
    {
      for(int j=0;j<n;j++)
      cout<<dp[i][j];
      cout<<endl;
    }*/
    for(i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
          if(s[j]==s[i])continue;
          int gap = j-i;
        int idx;
        char ch;
        if(s[i]!='R'&&s[j]!='R')
          {
            idx=0;
            ch = 'R';
          }
        if(s[i]!='G'&&s[j]!='G')
          {
            idx=2;
            ch = 'G';
          }
        if(s[i]!='B'&&s[j]!='B')
          {
            idx=1;
            ch = 'B';
          }

          ans+= dp[idx][j+1];
          if(2*j-i<n&&s[2*j-i]==ch)
            ans--;
          }
        //  debug(ans);
    }
    cout<<ans;


  }
  return 0;
}


Measured memory_bytes: 6056