fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    var r = 0
    var g = 0
    var b = 0

    var result = 0L
    var sub = 0L
    for(i in 0 until n){
        when{
            s[i] == 'R' -> r++
            s[i] == 'G' -> g++
            s[i] == 'B' -> b++
        }
    }
    result = r * g * b.toLong()

    for(i in 0 until n){
        for(j in i + 1 until n){
            if(s[i] != s[j] && 2 * j - i < n){
                if(s[i] != s[2 * j - i] && s[j] != s[2 * j - i]) sub++;
            }
        }
    }

    println(result - sub)
}
