fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    var rCount = 0L
    var gCount = 0L
    var bCount = 0L
    for(i in 0 until n) {
        when (s[i]) {
            'R' -> rCount++
            'G' -> gCount++
            'B' -> bCount++
        }
    }

    var patternCount = rCount * gCount * bCount
    for (i in 0 until n) {
        for (j in (i + 1) until n) {
            val k = (2 * j) - i
            if (k >= n) continue
            if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) patternCount--
        }
    }

    println(patternCount)
}