fun main() = abc166e()

@OptIn(ExperimentalStdlibApi::class)
fun abc166e() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val appeared = mutableMapOf<Long, Long>().withDefault { 0 }
    var answer = 0L

    for ((index, a) in aList.withIndex()) {
        answer += appeared.getValue(index - a)
        appeared[a + index] = appeared.getValue(a + index) + 1
    }

    println(answer)
}
