program main
   implicit none
   integer::N
   integer,allocatable,dimension(:)::L
   integer::i,j
   integer::ok,ng,med
   integer::cnt=0
   read*,N
   allocate(L(N))
   read*,L
   call heapsort(N,L)
   do i=N,3,-1
      do j=i-1,2,-1
         if(L(i)<L(j)+L(1))then
            cnt=cnt+j-1
            cycle
         endif
         ok=j;ng=1
         med=(ok+ng)/2
         do while(ok-ng>1)
            if(check(L(i),L(j),L(med)))then
               ok=med
            else
               ng=med
            endif
            med=(ok+ng)/2
         end do
         cnt=cnt+j-ok
      end do
   end do
   print"(i0)",cnt
contains
logical function check(a,b,x)
   integer::a,b,x
   check=(b+x>a)
end

subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  integer::i,k,j,l
  integer:: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort

end program main