import Data.Vector.Unboxed((!),fromList)
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
binarySearch :: (Int -> Bool) -> Int -> Int -> Int
binarySearch pred ok ng
  | abs (ok-ng) <= 1 = ok
  | pred mid = binarySearch pred mid ng
  | otherwise = binarySearch pred ok mid
    where mid = (ok+ng) `div` 2

main = do
    n <- readLn :: IO Int
    l <- fromList . sort <$> getIntList
    let list = [max 0 (right-left+1) |
           i <- [0 .. n - 3],
           let a = l ! i,
           j <- [i + 1 .. n - 2],
           let b = l ! j,
           -- condition :: l!k < a+b,abs (a-b) < l!k , j < k
           let left = binarySearch (\k -> abs (a-b) < l ! k) (n-1) j,
           let right = binarySearch (\k -> l ! k < a+b) 0 n
           ]
    print $ sum list
