fun main() {
	readLine()
	val a = readLine()!!.split(" ").map {it.toInt()}
	val m = mutableMapOf<Int,Long>()
	println(a.withIndex().reversed().map {(i,v)->
		m[i-v] = (m[i-v] ?: 0)+1
		m[i+v] ?: 0L
	}.sum())
}
