let N = Int(readLine()!)!

let nums: [Int] = readLine()!.split(separator: " ").map { Int($0)! }

var table: [Int: Set<Int>] = [:]

var count = 0
for i in 0..<nums.count {
  	for (key, value) in table {
      let sum = key + nums[i]
      let c1 = i - sum
      let c2 = i + sum
      if value.contains(c1) || value.contains(c2) {
        count += 1
      }
    }
	table[nums[i], default: Set<Int>()].insert(i)
}
print(count)