"use strict";
function main(input) {
  const n = parseInt(input[0]);
  const s = input[1].trim().split("");
  const rgb = { "R":0, "G":0, "B":0 };

  for(let i of s){
    rgb[i]++;
  }

  let sum = rgb.R * rgb.G * rgb.B;

  for(let i=1;i<n;i++){
    for(let j=2;j<n;j++){
      let checker = [s[j-i], s[j], s[j+i]].sort(); 
      if(checker.join("") === "BGR"){
        sum--;
      }
    }
  }
  console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));