import Data.List

main = do
  n <- (read :: String -> Int) <$> getLine
  a <- sort . map (read :: String -> Int) . words <$> getLine
  b <- sort . map (read :: String -> Int) . words <$> getLine
  c <- sort . map (read :: String -> Int) . words <$> getLine
  print . sum $ zipWith (*) (scanl1 (+) $ ltList a b) (gtList (length c) c b)


ltList :: [Int] -> [Int] -> [Int]
ltList _  []     = []
ltList [] (b:bs) = 0 : ltList [] bs
ltList a  (b:bs) = let lt = length $ takeWhile (< b) a
                       remain = drop lt a
                   in lt : ltList remain bs

gtList :: Int -> [Int] -> [Int] -> [Int]
gtList n _  []     = []
gtList n [] (b:bs) = 0 : gtList n [] bs
gtList n a  (b:bs) = let le =  length $ takeWhile (<= b) a
                         remain = drop le a
                     in (n-le) : gtList (n-le) remain bs
