#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>
 
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)
 
int main() {
  ll N;
  string S;
  cin >> N >> S;
  vector<ll> 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);
  }
      
  ll sum = 0;
  
  for (int i=0; i < R.size(); i++){
    for(int j=0; j < G.size(); j++){
      if(R[i]<G[j]){
        auto Iter1 = upper_bound(B.begin(), B.end(), G[j]);
        if(binary_search(B.begin(), B.end(), 2*G[j]-R[i]) ){
          sum += (B.end() - Iter1 - 1);
          //cout << B.end() - Iter1 - 1 << endl;
        }else{
          sum += (B.end() - Iter1);
          //cout << B.end() - Iter1 << endl;
        }
      }
    }
  }

  for (int i=0; i < G.size(); i++){
    for(int j=0; j < R.size(); j++){
      if(G[i]<R[j]){
        auto Iter1 = upper_bound(B.begin(), B.end(), R[j]);
        if(binary_search(B.begin(), B.end(), 2*R[j]-G[i]) ){
          sum += (B.end() - Iter1 - 1);
          //cout << B.end() - Iter1 - 1 << endl;
        }else{
          sum += (B.end() - Iter1);
          //cout << B.end() - Iter1 << endl;
        }
      }
    }
  }  

  for (int i=0; i < R.size(); i++){
    for(int j=0; j < B.size(); j++){
      if(R[i]<B[j]){
        auto Iter1 = upper_bound(G.begin(), G.end(), B[j]);
        if(binary_search(G.begin(), G.end(), 2*B[j]-R[i]) ){
          sum += (G.end() - Iter1 - 1);
          //cout << B.end() - Iter1 - 1 << endl;
        }else{
          sum += (G.end() - Iter1);
          //cout << B.end() - Iter1 << endl;
        }
      }
    }
  }
  
  for (int i=0; i < B.size(); i++){
    for(int j=0; j < R.size(); j++){
      if(B[i]<R[j]){
        auto Iter1 = upper_bound(G.begin(), G.end(), R[j]);
        if(binary_search(G.begin(), G.end(), 2*R[j]-B[i]) ){
          sum += (G.end() - Iter1 - 1);
          //cout << B.end() - Iter1 - 1 << endl;
        }else{
          sum += (G.end() - Iter1);
          //cout << B.end() - Iter1 << endl;
        }
      }
    }
  }
  
  for (int i=0; i < B.size(); i++){
    for(int j=0; j < G.size(); j++){
      if(B[i]<G[j]){
        auto Iter1 = upper_bound(R.begin(), R.end(), G[j]);
        if(binary_search(R.begin(), R.end(), 2*G[j]-B[i]) ){
          sum += (R.end() - Iter1 - 1);
          //cout << B.end() - Iter1 - 1 << endl;
        }else{
          sum += (R.end() - Iter1);
          //cout << B.end() - Iter1 << endl;
        }
      }
    }
  }  

  for (int i=0; i < G.size(); i++){
    for(int j=0; j < B.size(); j++){
      if(G[i]<B[j]){
        auto Iter1 = upper_bound(R.begin(), R.end(), B[j]);
        if(binary_search(R.begin(), R.end(), 2*B[j]-G[i]) ){
          sum += (R.end() - Iter1 - 1);
          //cout << B.end() - Iter1 - 1 << endl;
        }else{
          sum += (R.end() - Iter1);
          //cout << B.end() - Iter1 << endl;
        }
      }
    }
  }
  
  cout << sum << endl;
  
}