fun main(args: Array<String>) = abc162d()

fun abc162d() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val counts = LongArray(3)
    s.forEach { counts[it.toInt() % 3]++ }

    var removeCount = 0L

    for (left in 0 until n) {
        for (mid in left + 1 until n) {
            val right = mid + (mid - left)
            if (right !in s.indices) break
            if (setOf(s[left], s[mid], s[right]).size == 3) removeCount++
        }
    }

    val answer = counts[0] * counts[1] * counts[2] - removeCount

    println(answer)
}
