"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
function lower_bound(d,e,a,b){for(var c;1<b-a;)d[c=a+b>>1]<e?a=c:b=c;return d[a]<e?b:a};

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next();
  var s = next(1);
  var ans = 0;
  var r = [], g = [], b = [];
  var rs = new Set(),gs = new Set(),bs = new Set();
  for(var i = 0; i < n; i++){
    if(s[i] === "R")r.push(i),rs.add(i);
    else if(s[i] === "G")g.push(i),gs.add(i);
    else b.push(i),bs.add(i);
  }
  for(i = 0; i < r.length; i++){
    var m = r[i];
    for(var j = 0, q = g[0]; j < g.length && q < m; j++, q = g[j]){
      var z = b.length-lower_bound(b,m,0,b.length);
      if(bs.has(m+m-q))z--;
      ans += z;
    }
    for(var j = 0, q = b[0]; j < b.length && q < m; j++, q = b[j]){
      var z = g.length-lower_bound(g,m,0,g.length);
      if(gs.has(m+m-q))z--;
      ans += z;
    }
  }
  for(i = 0; i < g.length; i++){
    var m = g[i];
    for(var j = 0, q = r[0]; j < r.length && q < m; j++, q = r[j]){
      var z = b.length-lower_bound(b,m,0,b.length);
      if(bs.has(m+m-q))z--;
      ans += z;
    }
    for(var j = 0, q = b[0]; j < b.length && q < m; j++, q = b[j]){
      var z = r.length-lower_bound(r,m,0,r.length);
      if(rs.has(m+m-q))z--;
      ans += z;
    }
  }
  for(i = 0; i < b.length; i++){
    var m = b[i];
    for(var j = 0, q = g[0]; j < g.length && q < m; j++, q = g[j]){
      var z = r.length-lower_bound(r,m,0,r.length);
      if(rs.has(m+m-q))z--;
      ans += z;
    }
    for(var j = 0, q = r[0]; j < r.length && q < m; j++, q = r[j]){
      var z = g.length-lower_bound(g,m,0,g.length);
      if(gs.has(m+m-q))z--;
      ans += z;
    }
  }
  return ans;
}