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

int main(){
	int n;
    string s;
	cin >> n>>s;
    vector<int>r,g,b;
    int kazu_r=0;
    int kazu_g=0;
    int kazu_b=0;
	for (int i = 0;i < n;i++) {
      if(s[i]=='R'){
        r.push_back(i);
        //cout<<"R"<<i<<endl;
        kazu_r++;
      }else if(s[i]=='G'){
        g.push_back(i);
        kazu_g++;
      }else{
        b.push_back(i);
        kazu_b++;
      }
	}
    //cout<<kazu_r<<" "<<kazu_g<<" "<<kazu_b<<endl;
	long long kotae = 0;
    int dai=0;
    int mid=0;
    int shou=0; 
	for (int i = 0;i <kazu_r;i++) {
	  for (int j = 0;j <kazu_g;j++) {
	    for (int k = 0;k <kazu_b;k++) {
          
          dai=max(r[i],max(g[j],b[k]));
          shou=min(r[i],min(g[j],b[k]));
          mid=r[i]+g[j]+b[k]-dai-shou;
          //cout<<dai<<" "<<mid<<" "<<shou<<endl;
          if(mid-shou!=dai-mid){
            kotae++;
          }
        }
      }
	}
	cout << kotae << endl;
	return 0;
}