import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad

main :: IO ()
main = readLn >>= main'
    where
        main' n = replicateM 3 breads >>= print . solve n . fmap sort

solve :: Int -> [[Int]] -> Int 
solve n [as, bs, cs] = check2 as $ check n bs cs
    where
        check cn (x : xs) (y : ys)
            | x < y = (x, cn + v) : next
            | otherwise = check (cn - 1) (x : xs) ys
            where
                next@((_, v) : _) = check cn xs $ y : ys
        check _ _ _ = [(0, 0)]

        check2 (x : xs) yys@((y, v) : ys)
            | x < y = v + check2 xs yys
            | otherwise = check2 (x : xs) ys
        check2 _ _ = 0
        
breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)