let n = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map { Int($0)! }

var iDict = [Int: Int]()
var jDict = [Int: Int]()

a.enumerated().forEach { (i, v) in
  iDict[i+v] = iDict[i+v] ?? 0
  iDict[i+v]? += 1
  jDict[i-v] = jDict[i-v] ?? 0
  jDict[i-v]? += 1
}

var c = 0
iDict.forEach { (v, iIndicesNum) in
  let jIndicesNum = jDict[v] ?? 0
  c += iIndicesNum * jIndicesNum
}

print(c)
