      PROGRAM Triangles
      IMPLICIT NONE
      INTEGER :: N
      INTEGER,ALLOCATABLE :: L(:)
      INTEGER(8) :: ans
      INTEGER :: a,b,c, cmin,cEnd
      read*,N
      ALLOCATE( L(1:N) )
      read*,L(:)
      
      CALL bubbleSort( L,N )
      
      ans = 0
      DO a = 1,N-2
        DO b = a+1,N-1
        cmin = L(a) - L(b)
        cEnd = b
          DO c = N,b+1,-1
            IF( L(c)>cmin )THEN
              cEnd = c
              EXIT
            END IF
          END DO
          ans = ans + (cEnd-(b+1)+1)
        END DO
      END DO
      
      print*,ans
      
      
      END PROGRAM
      
      SUBROUTINE bubbleSort( array,N )
        IMPLICIT NONE
        INTEGER,INTENT(INOUT) :: array(1:N)
        INTEGER :: N
        INTEGER :: a,b,buffer
        
        N = size( array )
        DO a = 1,N-1
          DO b = a+1,N
            !left will be BIG
            IF( array(a)<array(b) )THEN
              buffer   = array(a)
              array(a) = array(b)
              array(b) = buffer
            END IF
          END DO
        END DO
      END SUBROUTINE bubbleSort