
fun main(){
    val N = readLine()!!.toInt()
    val S = readLine()!!

    var r: Long = 0
    var g: Long = 0
    var b: Long = 0
    for(c in S){
        if (c == 'R') {
            r += 1
        } else if (c == 'G'){
            g += 1
        } else{
            b += 1
        }
    }
    
    var sub: Long = 0
    for(i in 0 until N){
        for(j in i+1 until N){
            if (S[i] == S[j]) continue
            val k = 2 * j - i
            if (k >= N || S[i] == S[k] || S[j] == S[k]) continue;
            sub += 1
        }
    }

    val ans: Long = r * g * b - sub
    println(ans)

}