program main
    implicit none
    integer n,i,j,x
    integer,allocatable::a(:)
    read(*,*) n
    allocate(a(n))
    read(*,*) a(1:n)
    x=0
    do i=1,n
        if(a(i)>2*10**5) a(i)=0
    end do
    i=0
    do i=1,n-2
        if(a(i)==0) cycle
        do j=2,n-i
            if(a(i+j)==0) cycle
            if(a(i)+a(i+j)==j) x=x+1
        end do
    end do
    write(*,*) x
end program main
