fun main(arg: Array<String>) {
    val (R, G, B) = listOf(0, 1, 2)
    val N = nextInt()
    val S = next()
    val A = S.map {
        when(it) {
            'R' -> 0
            'G' -> 1
            'B' -> 2
            else -> 999
        } }
    val RGB = Array(3) { IntArray(N) }
    A.forEachIndexed { index, ch -> RGB[ch][index] = 1 }
    for (m in 0 until 3)
        for (n in (1 until N).reversed()) RGB[m][n - 1] += RGB[m][n]
    fun get(c: Int, n: Int, m: Int): Int {
        var p = RGB[c][m + 1]
        if (p > 0 && m + (m - n) < N && c == A[m + (m - n)]) p -= 1
        return p
    }
    fun getC(n: Int, c1: Int, c2: Int): Long {
        var c = 0L
        for (m in n + 1 until N - 1) {
            when (A[m]) {
                c1 -> c += get(c2, n, m)
                c2 -> c += get(c1, n, m)
                else -> { }
            }
        }
        return c
    }
    var ans = 0L
    for (n in 0 until N - 2) {
        when (A[n]) {
            R -> { ans += getC(n, G, B) }
            G -> { ans += getC(n, B, R) }
            B -> { ans += getC(n, G, R) }
        }
    }
    return 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) }
