fun main(arg: Array<String>) {
    val N = nextInt()
    val S = next()
    var (R, G, B) = listOf<Long>(0, 0, 0)
    S.forEach {
        when (it) {
            'R' -> R += 1
            'G' -> G += 1
            'B' -> B += 1
            else -> { }
        }
    }
    val total = R * G * B
    var exc = 0L
    for (n in 0 until N - 2) {
        for (m in n + 1 until N - 1) {
            val k = m + (m - n)
            if (k >= N) continue
            if (S[n] != S[m] && S[n] != S[k] && S[m] != S[k]) exc += 1
        }
    }
    val ans = total - exc
    println(ans)
}

fun next() = readLine()!!
fun nextInt(offset: Int = 0) = Integer.parseInt(next()) + offset
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfDouble() = listOfString().map(String::toDouble)
fun listOfInt(offset: Int = 0) = listOfString().map { Integer.parseInt(it) + offset }
fun listOfInt(vararg offset: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + offset[index % offset.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + offset }
fun listOfLong(vararg offset: Long) = listOfString().map { java.lang.Long.parseLong(it) }.mapIndexed { index, long -> long + offset[index % offset.size] }
fun listOfDouble(offset: Double = 0.0) = listOfString().map { java.lang.Double.parseDouble(it) + offset }
fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }
