import Control.Monad
import Data.List
sort' = sortBy (flip compare)
main = do
    n <- readLn
    ss <- (map ((map read) . words)) <$> replicateM 3 getLine
    print $ solve n ss
solve :: Int -> [[Int]] -> Int
solve n (a:b:c:d) = f b (sort a) (sort' c)
f [] b c = 0
f (a:as) b c = (h (>a) c) * (h (<a) b) + f as b c where
    h _ [] = 0
    h f (a:as)
        | f a = 1 + h f as
        | otherwise = 0