n=io.read("*n","*l")
a={}
l={}
r={}
for i=1,n do
    a[i]=io.read("*n")
    if not l[i+a[i]] then
        l[i+a[i]]=1
    else
        l[i+a[i]]=l[i+a[i]]+1
    end
    if not r[i-a[i]] then
        r[i-a[i]]=1
    else
        r[i-a[i]]=r[i-a[i]]+1
    end
end

combination=0
for i,_ in pairs(l) do
    if r[i] then
        combination=combination+l[i]*r[i]
    end
end
print(combination)