#include <bits/stdc++.h>
#include <set>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)  

void greatFirst(ll& a, ll& b)
{
  if(a < b)
  {
    ll tmp = a;
    a = b;
    b = tmp;
  }
}

ll gcd(ll a, ll b)
{
  greatFirst(a, b);
  
  while(a % b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  
  return b;
}

int main()
{
  int n;
  string s;
  cin >> n >> s;
  
  vector<int> r, g, b;
  rep(i, n)
  {
    if(s[i] == 'R')
    {
      r.push_back(i);
    }
    else if(s[i] == 'G')
    {
      g.push_back(i);
    }
    else
    {
      b.push_back(i);
    }
  }
  
  if(r.size() == 0 || g.size() == 0 || b.size() == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  
  ll out = 0;
  for(auto ri : r)
  {
    for(auto gi : g)
    {
      for(auto bi : b)
      {
        int sub1 = abs(ri - bi);
        int sub2 = abs(ri - gi);
        int sub3 = abs(bi - gi);
        if(sub1 == sub2 || sub2 == sub3 || sub1 == sub3)
        {
          out++;
        }
      }
    }
  }
  
  ll ans = r.size() * g.size() * b.size() - out;
  cout << fixed << ans << endl; 
  
  return 0;
}
