"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const n = parseInt(input[0]);
    const s = input[1];
    let rs = []
    let gs = []
    let bs = []
    for(let i = 0; i<s.length;i++){
        if(s[i] === "R") rs.push(i)
        else if(s[i] === "G") gs.push(i) 
        else if(s[i] === "B") bs.push(i)
    }
    let num = rs.length * gs.length * bs.length
    for(let i = 0; i< n; i++){
        for(let j = i+1; j<n; j++){
            let k = j + j - i
            if (k >= n) break
            if( s[i] !== s[j] && s[j] !== s[k] && s[k] !== s[i]){
                num--
            }
        }
    }
    console.log(num)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  