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