import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val n = readInputLine().toInt()
    val s = readInputLine().toCharArray()

    val rCnt = s.count { it == 'R' }.toLong()
    val gCnt = s.count { it == 'G' }.toLong()
    val bCnt = s.count { it == 'B' }.toLong()

    var ans = rCnt * bCnt * gCnt

    for (i in s.indices) {
        for (j in i - 1 downTo 0) {
            if (i - (i - j) * 2 < 0) {
                break
            }
            if (s[i] != s[j] && s[i] != s[i - (i - j) * 2] && s[j] != s[i - (i - j) * 2]) {
                ans--
            }
        }
    }

    pw.println(ans)

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}
