#include <bits/stdc++.h>
using namespace std;


#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  string s ;
  cin >> n >> s ;
  
  vector<int> r ;
  vector<int> g ;
  vector<int> b ;
  rep(m,s.size()){
    if( s.at(m) == 'R')
      r.push_back(m+1);
     if( s.at(m) == 'B')
      b.push_back(m+1);
     if( s.at(m) == 'G')
      g.push_back(m+1);
  }
  
  intll ans = 0;
  rep(i,r.size()){
    rep(j,b.size()){
      rep(k,g.size()){
        vector<int> v(3) ;
        v.at(0) = b.at(j) ;
        v.at(1) = r.at(i) ;
        v.at(2) = g.at(k) ;
        sort(all(v));
        
        if(v.at(1) - v.at(0)  != v.at(2)-v.at(1) ) ans ++ ;
     
      }
    }
  }
  
  cout << ans ;

}
