fun main() {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toInt).toIntArray()
    var count = 0L

    // i < j
    // j - i = a_j + a_i
    // j - a_j = a_i + i
    // ansJ = j - a_j
    // ansI = i + a_i
    val map = mutableMapOf<Int, Long>()
    for (i in an.indices) {
        // ansJ = j - a_j
        val ansJ = i - an[i]
        count += map[ansJ] ?: 0L

        val ansI = i + an[i]
        map[ansI] = (map[ansI] ?: 0) + 1
    }

    println(count)
}



