program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,i,j,ans,ii,jj
    integer(int64), allocatable:: a(:), ia(:), ja(:)

    read*, n
    allocate(a(n),ia(n),ja(n))
    read*, a(:)
    do i=1,n
        ia(i) = a(i)+i
        ja(i) = -a(i)+i
    end do
    ans=0
    call merge_sort(ia,1,n)
    call merge_sort(ja,1,n)

    i=1
    j=1

    do while(i <= n .and. j<=n)
        if (ia(i) == ja(j))then
            ii=0
            do while(ia(i) == ia(i+ii))
                ii=ii+1
                if (i+ii > n) exit
            end do
            jj=0
            do while(ja(j)==ja(j+jj))
                jj=jj+1
                if (j+jj > n)exit
            end do
            ans=ans+ii*jj
            i=i+ii
            j=j+jj
        else if (ia(i) > ja(j)) then
            j=j+1
        else
            i=i+1
        end if
    end do
    print'(i0)', ans


contains
recursive subroutine merge_sort(ar, fst, lst)
    integer(int32),intent(inout):: ar(:)
    integer(int32),intent(in):: fst,lst
    integer(int32):: mdl

    if (lst-fst < 2) then
        if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
        return
    end if

    mdl = (fst+lst)/2
    call merge_sort(ar, fst, mdl)
    call merge_sort(ar, mdl+1, lst)
    call merge_(ar, fst, mdl, lst)
end subroutine

subroutine merge_(ar, fst, mdl, lst)
    integer(int32),intent(inout):: ar(:)
    integer(int32),intent(in):: fst, mdl, lst
    integer(int32),allocatable:: tmp(:)
    integer(int32):: li, ri, ti

    allocate(tmp(lst-fst+1))

    li=fst
    ri=mdl+1   
    ti=1

    do while (li <= mdl .and. ri <= lst)
        if (ar(li) <= ar(ri)) then
            tmp(ti) = ar(li)
            li=li+1
        else
            tmp(ti) = ar(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (li <= mdl) then
        tmp(ti:) = ar(li:mdl)
    else
        tmp(ti:) = ar(ri:lst)
    end if

    ar(fst:lst) = tmp(:)
    deallocate(tmp)
end subroutine

subroutine swap(x,y)
    integer(int32),intent(inout):: x,y
    integer(int32):: tmp
    tmp = x
    x = y
    y = tmp
end subroutine
    

end program name