#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
using namespace std; 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() << x; }
template<typename T> void db(T x , T y){ debug() << x <<" "<< y; }
template<typename T> void db(T x , T y , T z){ debug() << x <<" "<< y <<" "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() << x <<" " << y <<" "<< z <<" "<< a; }

const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

string tx = "RGB";
char pos(char a , char b){
  for(char i : tx){
    if(i != a && i != b){
      return i;
    }
  }
}
int dis(char a , char b , char c){
  if(a != b && a != c && b != c) return 1;
  return 0;
}
int brute(string &s){
  int n = s.size();
  int cnt = 0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(dis(s[i] , s[j] , s[k])){
          cnt++;
        }
      }
    }
  }
  return cnt;
}
int brute2(string &s){
  int n = s.size();
  int cnt = 0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(dis(s[i] , s[j] , s[k]) && (j - i == k - j)){
          cnt++;
        }
      }
    }
  }
  return cnt;
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int>Bc,Gc,Rc;
  Bc = Gc = Rc = vector<int>(N,0);
  int cntr = 0 , cntb = 0 , cntg = 0;
  for(int i=N-1;i>=0;i--){
    cntr += (S[i] == 'R');
    cntb += (S[i] == 'B');
    cntg += (S[i] == 'G');

    Rc[i] = cntr;
    Gc[i] = cntg;
    Bc[i] = cntb;
  }

  vector<int>rind , gind , bind;

  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(S[i] != S[j]){
        char c = pos(S[i], S[j]);
        // dg2(i , j);
        // dg3(S[i] , S[j] , c);
        if(c == 'R'){
          rind.push_back(j);
        }
        else if(c == 'B'){
          bind.push_back(j);
        }
        else gind.push_back(j);
      }
    }
  }

  int tot = 0;
  // dg(rind);
  // dg(gind);
  // dg(bind);
  for(int i : rind) tot += Rc[i];
  for(int i : bind) tot += Bc[i];
  for(int i : gind) tot += Gc[i];
  dg2(tot , brute(S));
  int sub = 0;
  for(int i=1;i<N-1;i++){
     int l = i-1 , r = i+1;
     while(l>=0 && r < N){
       if(dis(S[l] , S[i], S[r])) sub++;
       l--;
       r++;
     }
  }

  dg2(sub , brute2(S));

  int ans = tot - sub;
  cout << ans << '\n';

}

Measured memory_bytes: 55040