fun main() {
    readInt()

    fun howMany(j: Int, left: List<Int>, right: List<Int>): Long {
        var num = 0L
        for (i in left) {
            if (i > j) break
            val forbidden = j + j - i
            val findForbidden = right.binarySearch(forbidden)
            val startIndex = -(right.binarySearch(j) + 1)
            num += (right.size - startIndex)
            if (findForbidden >= 0) num--
        }
        return num
    }
    val s = readLn()

    val r = mutableListOf<Int>()
    val g = mutableListOf<Int>()
    val b = mutableListOf<Int>()

    s.forEachIndexed { index, c ->
        when(c) {
            'R' -> r.add(index)
            'G' -> g.add(index)
            'B' -> b.add(index)
        }
    }

    var ans = 0L
    for (j in 1 until s.length - 1) {
        when(s[j]) {
            'R' -> {
                ans += howMany(j, g, b)
                ans += howMany(j, b, g)
            }
            'G' -> {
                ans += howMany(j, r, b)
                ans += howMany(j, b, r)
            }
            'B' -> {
                ans += howMany(j, r, g)
                ans += howMany(j, g, r)
            }
        }
    }

    println(ans)
}

// Input Reader
private fun readLn() = readLine()!!
// Read from file
//private val inputReader = InputStreamReader(FileInputStream(File("input.txt")))
//private val lines = inputReader.readLines()
//private var currLine = -1
//private fun readLn(): String {
//    currLine++
//    return lines[currLine]
//}

private fun readInt() = readLn().toInt()
