fun main(){
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val k = readLine()!!.split(" ")[0].toCharArray()
    val rIndex = mutableListOf<Int>()
    val gIndex = mutableListOf<Int>()
    val bIndex = mutableListOf<Int>()
    for (i in 0 until n){
        if (k[i] == 'R'){
            rIndex.add(i)
        } else if (k[i] == 'G'){
            gIndex.add(i)
        } else {
            bIndex.add(i)
        }
    }
    val r = rIndex.size
    val g = gIndex.size
    val b = bIndex.size
    var ans:Long = r.toLong() * g * b
    for (i in 0 until n){
        for (j in 1 until n){
            if (i + j > k.size - 1 || i - j < 0){
                break
            }
            if (k[i] == 'R'){
                if (k[i + j] == 'G' && k[i - j] == 'B'){
                    ans -= 1
                } else if (k[i + j] == 'B' && k[i - j] == 'G'){
                    ans -= 1
                }
            } else if (k[i] == 'G'){
                if (k[i + j] == 'R' && k[i - j] == 'B'){
                    ans -= 1
                } else if (k[i + j] == 'B' && k[i - j] == 'R'){
                    ans -= 1
                }
            } else {
                if (k[i + j] == 'G' && k[i - j] == 'R'){
                    ans -= 1
                } else if (k[i + j] == 'R' && k[i - j] == 'G'){
                    ans -= 1
                }
            }
        }
    }
    println(ans)
}
