fun main() {
    readLine()
    val a = readLine()!!.split(' ').map { it .toInt() }
    var mapL: MutableMap<Int, Long> = mutableMapOf()
    var mapR: MutableMap<Int, Long> = mutableMapOf()
    a.forEachIndexed { idx, value ->
        val l = idx-value
        val r = idx+value
        if (!mapL.containsKey(l)) mapL[l] = 0L
        if (!mapR.containsKey(r)) mapR[r] = 0L
        mapL[l] = mapL[l]!!+1
        mapR[r] = mapR[r]!!+1
    }
    var cnt = 0L
    for (x in mapL.keys) {
        if (mapR.containsKey(x)) cnt += mapL[x]!!*mapR[x]!!
    }
    println(cnt)
}
