program ABC142D
    implicit none
    integer(8) ::N,i,j
    integer(8) ::c
    integer(8) ::result
    integer(8),allocatable,dimension(:)::L

    read (5,*) N
    result=N*(N-1)*(N-2)/6
    allocate(L(N))
    read (5,*) (L(i),i=1,N)
    L=iqsort(L)

    do i=1,N-2
        do j=i+1,N-1
            c=L(N+1-i)-L(N+1-j)
            result=result-min(N-j,upper_bound(L,N,c)-1)
        end do
    end do

    print'(i0)',result

contains  
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort

    function upper_bound(A,N,s) result(place)
      integer(8),intent(in)::A(:),N,s
      integer(8)::place,t,e,c

      t=0
      e=N

      do
          if(e-t<=1) then
              exit
          end if

          c=(t+e)/2
          if(A(c)>s) then
              e=c
          else if(A(c)<=s) then
              t=c
          end if
      end do
      place=e
    end function upper_bound
end program ABC142D