"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)
        if(s[i] === "G") gs.push(i) 
        if(s[i] === "B") bs.push(i)
    }
    let cnt = 0
    for(let r of rs){
        for(let g of gs){
            for(let b of bs){
                let tmp = [r,g,b]
                tmp.sort()
                let [s,m,l] = tmp
                if(m-s !== l-m) cnt++
            }
        }
    }
    console.log(cnt)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  