"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1].split("");
    
    let r = 0;
    let g = 0;
    let b = 0;
    
    for(let i=0; i<N; i++) {
        if(S[i] === "R") {
            r++;
        }
        
        if(S[i] === "G") {
            g++;
        }
        
        if(S[i] === "B") {
            b++;
        }
    }
    
    let answer = r * g * b;

    for(let i=0; i<N; i++) {
        for(let j=i+1; j<N; j++) {
            if(S[i] === S[j]) continue;
            
            let k = j + (j - i);
            
            if(k >= N) continue;
            
            // console.log(S[i])
            // console.log(S[j])
            // console.log(S[k])
            // console.log("-----")
            
            // 等差数列になっているものを引く
            if(S[j] !== S[k] && S[i] !== S[k]) {
                answer--;
            }
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));