fun main() {
    val n = readLine()?.toInt() ?: return
    val s = readLine() ?: return
    val r = hashMapOf<Int, Long>()
    val g = hashMapOf<Int, Long>()
    val b = hashMapOf<Int, Long>()
    repeat(n) {
        val i = n - it - 1
        r[i] = r.getOrDefault(i + 1, 0L)
        g[i] = g.getOrDefault(i + 1, 0L)
        b[i] = b.getOrDefault(i + 1, 0L)
        when (s[i]) {
            'R' -> {
                r[i] = r.getOrDefault(i, 0L) + 1
            }
            'G' -> {
                g[i] = g.getOrDefault(i, 0L) + 1
            }
            'B' -> {
                b[i] = b.getOrDefault(i, 0L) + 1
            }
        }
    }

    fun counter(s: String, i: Int, j: Int, diff: Int, a: Char, b: Char, c: Char, cMap: Map<Int, Long>): Long {
        return if (s[i] == a && s[j] == b || s[i] == b && s[j] == a) {
            (cMap[j] ?: 0L) - if (s.getOrNull(j + diff) == c) {
                1L
            } else {
                0L
            }
        } else {
            0L
        }
    }
    var count = 0L
    0.until(n - 2).forEach { i ->
        (i + 1).until(n - 1).forEach { j ->
            if (s[i] != s[j] && i < j) {
                val diff = j - i
                count += counter(s, i, j, diff, 'B', 'G', 'R', r) +
                        counter(s, i, j, diff, 'R', 'B', 'G', g) +
                        counter(s, i, j, diff, 'R', 'G', 'B', b)
            }
        }
    }
    println(count)
}
