import Control.Monad
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 where
    f [] = 0
    f (x:xs) = fil' (x<) c * fil' (x>) a + f xs
    fil' _ []    = 0
    fil' g (x:xs)
      | g x         = 1 + fil' g xs
      | otherwise      = 0 + fil' g xs