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

let As = inp.enumerated().map { i, n -> (Int, Int, Int, Int) in
    return (i+1, n, i+n, i-n)
}

let dic2 = Dictionary(grouping: As, by: \.2)
let dic3 = Dictionary(grouping: As, by: \.3)


var r = 0
for i in As {
    let r2 = (dic2[i.3] ?? []).count
    let r3 = (dic3[i.2] ?? []).count
    r += r2 + r3
}

print(r/2)
