fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val l = readLine()!!
    var r=0L
    var g=0L
    var b=0L
    var result = 0L
    for(i in 0..n-1){
        when(l[i]){
            'R'->r++
            'G'->g++
            'B'->b++
        }
    }
    result = r*g*b
    if(result==0L){
        println(0)
        return
    }
    for(i in 0..n-1){
        for(s in 0..n-1){
            val j = i+s+1
            val k = j+s+1
            if(k<=n-1&&l[i] != l[j] && l[j] != l[k] && l[k]!=l[i]){
                result --
            }
        }
    }
    println(result)
}