-- Given two sequences a1, a2.. an (ai is the profit per click of the i-th ad) and b1, b2, . . . , bn (bi is
-- the average number of clicks per day of the i-th slot), we need to partition them into n pairs (ai, bi))
-- such that the sum of their products is maximized.

main :: IO ()
main =
  hSetBuffering stdin NoBuffering >>= \_ ->
  nextNum >>= \n ->
  nextNums n >>= \pc ->
  nextNums n >>= \ac ->
  let
    sortedPc = sortBy (flip compare) pc
    sortedAc = sortBy (flip compare) ac
    result   = sum $ zipWith (*) sortedPc sortedAc
  in putStrLn $ show $ result
main :: IO ()
main =
  hSetBuffering stdin NoBuffering >>= \_ ->
  nextNum >>= \n ->
  nextNums n >>= \pc ->
  nextNums n >>= \ac ->
  let
    sortedPc = sortBy (flip compare) pc
    sortedAc = sortBy (flip compare) ac
    result   = sum $ zipWith (*) sortedPc sortedAc
  in putStrLn $ show $ result
main =
  hSetBuffering stdin NoBuffering >>= \_ ->
  nextNum >>= \n ->
  nextNums n >>= \pc ->
  nextNums n >>= \ac ->
  let
    sortedPc = sortBy (flip compare) pc
    sortedAc = sortBy (flip compare) ac
    result   = sum $ zipWith (*) sortedPc sortedAc
  in putStrLn $ show $ result