fun isRGB(str: String, l: Int, m: Int, r: Int): Boolean {
    return str[l] != str[m] &&
            str[m] != str[r] &&
            str[r] != str[l]
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val input = readLine()!!

    val rn = input.filter { it == 'R' }.length.toLong()
    val gn = input.filter { it == 'G' }.length.toLong()
    val bn = input.filter { it == 'B' }.length.toLong()

    val w = (0 until n).map { m ->
        (1..n).map { d ->
            when {
                m - d < 0 -> 0
                m + d >= n -> 0
                isRGB(input, m - d, m, m + d) -> 1
                else -> 0
            }
        }.sum()
    }.sum()

    val answer = rn * gn * bn - w
    println(answer)
}