fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun <A> List<Comparable<A>>.upperBoundOf(target: A): Int {
        var l = -1
        var r = this.count()
        while (l + 1 < r) {
            val mid = (l + r) / 2
            if (this[mid] > target) {
                r = mid
            } else {
                l = mid
            }
        }
        return r
    }

    lateinit var count: (al: List<Int>, bl: List<Int>, cl: List<Int>) -> Long

    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val S = sc.next().toCharArray()
        val R = mutableListOf<Int>()
        val G = mutableListOf<Int>()
        val B = mutableListOf<Int>()
        repeat(N) { i ->
            when {
                S[i] == 'R' -> R += i
                S[i] == 'G' -> G += i
                S[i] == 'B' -> B += i
            }
        }

        count = { al, bl, cl ->
            var ans = 0L
            val cs = cl.toSet()
            al.forEach { a ->
                bl.forEach { b ->
                    if (a < b) {
                        ans += cl.count() - cl.upperBoundOf(b)
                        if (cs.contains(b + b - a)) {
                            ans--
                        }
                    }
                }
            }
            ans
        }

        var ans = 0L
        ans += count(R, G, B)
        ans += count(R, B, G)
        ans += count(G, B, R)
        ans += count(G, R, B)
        ans += count(B, R, G)
        ans += count(B, G, R)
        pw.println(ans)
    }
}
