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] ?? []
  iDict[i+v]?.append(i)
  jDict[i-v] = jDict[i-v] ?? []
  jDict[i-v]?.append(i)
}

var c = 0

iDict.forEach { (v, iIndices) in
  jDict[v]?.forEach { jIndex in
    iIndices.forEach { iIndex in
      if iIndex < jIndex {
        c += 1
      }
    }
  }
}

print(c)
