#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, n) for (size_t i = 0; i < (n); i++)
#define REP(n) FOR(i, n)
#define cinv(v, n) REP(n) {cin>>(v)[i];}
#define nvec(T, v, n) vector<T> v(n); cinv(v, n)
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
 
#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))
 
#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )
 
#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}
 
#define acm accumulate
#define pub push_back
#define pof pop_front
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))
 
#define GCD(v) gcd(ALL(v), 0l)
 
template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}
 
 
 
int main(){
  int n; string s;
  cin>>n>>s;
  int r=0,g=0,b=0;
  long long count = 0;
  for (size_t in = 0; in < n; in++) {
 
    if(s[in]=='R'){
      r++;
      count+=g*b;
      for (int i = in-2; i >= 0; i-=2) {
        if(i<0)break;
        if((s[i]=='G'&&s[(i+in)/2]=='B') || (s[i]=='B'&&s[(i+in)/2]=='G')){
          count--;
        }
      }
    }
 
    if(s[in]=='G'){
      g++;
      count+=r*b;
      for (int i = in-2; i >= 0; i-=2) {
        if(i<0)break;
        if((s[i]=='R'&&s[(i+in)/2]=='B') || (s[i]=='B'&&s[(i+in)/2]=='R')){
          count--;
        }
      }
    }
 
    if(s[in]=='B'){
      b++;
      count+=g*r;
      for (int i = in-2; i >= 0; i-=2) {
        if(i<0)break;
        if((s[i]=='G'&&s[(i+in)/2]=='R') || (s[i]=='R'&&s[(i+in)/2]=='G')){
          count--;
        }
      }
    }
 
    
  }
  cout<<count;
}
 
 
 
 
 
 
/* きょむ〜 */