fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val cCnt = mutableListOf<Cnt>()

    var prev = Cnt(0, 0, 0)
    s.forEach {
        val newCnt = when(it) {
            'R' -> Cnt(prev.r+1, prev.g, prev.b)
            'G' -> Cnt(prev.r, prev.g+1, prev.b)
            'B' -> Cnt(prev.r, prev.g, prev.b+1)
            else -> return
        }
        cCnt.add(newCnt)
        prev = newCnt
    }

    var ans = 0L

    for (i in 0..n-3) {
        inner@for (j in i+1..n-2) {
            if (s[j] == s[i]) continue@inner

            val last = "RGB".filter { it != s[i] && it != s[j] }
            val diff = j-i
            val sub = if (j+j-i < n && s[j+j-i] == last[0]) 1 else 0

            when(last) {
                "R" -> ans += cCnt[n-1].r - cCnt[j].r - sub
                "G" -> ans += cCnt[n-1].g - cCnt[j].g - sub
                "B" -> ans += cCnt[n-1].b - cCnt[j].b - sub
                else -> return
            }
        }
    }

    println(ans)
}

data class Cnt(val r: Int, val g: Int, val b: Int)