{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as UV

main :: IO()
main = do
  n <- readLn
  ns <- UV.fromList . sort <$> getIntList
  let f x k = (subtract k) . fst . bisearch ((< x) . (ns UV.!)) $ (k, n) 
  print . sum $ [ f x j | i <- [0..n-3], j <- [i+1..n-2], let x = (ns UV.! i) + (ns UV.! j)]


readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = BS.readInt . BS.dropWhile isSpace

getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine


-- 二分探索(整数)
bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check (left, right) = go (left, right)
 where
  go (l, r) | r - l == 1 = (l, r)
            | check mid  = go (mid, r)
            | otherwise  = go (l, mid)
    where mid = l + (r - l) `div` 2
