fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val r = s.count { it == 'R' }
    val g = s.count { it == 'G' }
    val b = s.count { it == 'B' }

    val exclude = (0..n-3).sumBy { l ->
        (1..n).count { w ->
            val c = l + w
            val r = c + w
            r < n && s[l] != s[c] && s[c] != s[r] && s[r] != s[l]
        }
    }

    println(1L * r * g * b - exclude)
}