import Data.List
import Control.Monad
import Data.IORef

main = do
  n <- readLn :: IO Int
  a <- getLine >>= return . reverse . sort . (map read) . words :: IO [Int]
  b <- getLine >>= return . reverse . sort . (map read) . words :: IO [Int]
  c <- getLine >>= return . reverse . sort . (map read) . words :: IO [Int]

  print $ sum $ g a b c

  where
    f [] _ _ = []
    f (x:xs) ys i = (i+len) : (f xs b (i+len))
      where
        (a,b) = span (>x) ys
        len = length a

    g as bs cs = h as bs 1
      where
        d = scanl (+) 0 $ f bs cs 0
        h [] _ _ = []
        h (x:xs) ys i = (d!!(i+len-1)) : (h xs b (i+len))
          where
            (a,b) = span (>x) ys
            len = length a
            
