const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {
 
    const lines = input.split('\n')
    const N = lines[0] - 0
    const S = lines[1]

    const RGB = {R: 0, G: 0, B: 0}
    for (let i = 0; i < N; i++) {
        RGB[S[i]]++
    }
    let sum = RGB.R * RGB.G * RGB.B

    for (let i = 0; i < N - 2; i++) {
        for (let j = i + 1; j < N - 1; j++) {
            let k = i + (j - i) * 2
            if (!S[k]) break
            if (
                S[i] !== S[j] &&
                S[i] !== S[k] &&
                S[j] !== S[k]
            ) {
                sum--
            }
        }
    }

    console.log(sum)

})(input)
