import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List (sortBy)

main :: IO ()
main = do
  (n  : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  ls <- sortBy (flip compare) . map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    x :: Int
    (_, _, x) = foldr step ([], [], 0) $ ls
    step :: Int -> ([Int], [Int], Int) -> ([Int], [Int], Int)
    step l (ls', ms', k) = let ms'' = filter (l <) ms' in (l : ls', map (l +) ls' ++ ms'', length ms'' + k)
  print x

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n
