fun main(args:Array<String>){
    val n = readLine()!!.toInt()
    val array = readLine()!!.split(" ").map {it.toLong()}
    val map = mutableMapOf<Long,Long>()
    var sum = 0L
    for(i in 1..n){
        val l = i-array[i-1]
        val r = i+array[i-1]
        map.put(r,map.getOrDefault(r,0)+1)
        sum+=map.getOrDefault(l,0)
    }
    println(sum)
}