fun main() = ABC162D.main()

object ABC162D {
    fun log(message: Any?) {
        //println(message)// TODO: ←消す
    }

    fun main() {
        val N = readInt()
        val S = readString()

        val rCount = S.filter { it == 'R' }.length
        val gCount = S.filter { it == 'G' }.length
        val bCount = S.filter { it == 'B' }.length

        val all = rCount.toLong() * gCount * bCount
        log("all=$all")

        var ignoreCount = 0L
        S.forEachIndexed { i, ic ->
            S.forEachIndexed { j, jc ->
                if (i >= j) return@forEachIndexed
                val k = j + j - i
                val kc = S.getOrNull(k)
                if (kc != null && ic != jc && jc != kc && kc != ic) {
                    ignoreCount++
                    log("ignore: $ic$jc$kc")
                }
            }
        }
        log("ignore=$ignoreCount")

        val ans = all - ignoreCount
        println(ans)
    }


    /*####################################################################################*/

    fun readString() = readLine()!!
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map { it.toInt() }
}