module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap.Strict as M

readi b | Just (n, _) <- B.readInt b = n

solve :: M.IntMap Int -> [Int] -> M.IntMap Int -> Int
solve as bs cs = foldr f 0 bs
  where
    f b acc
        | isNothing ma || isNothing mc = acc
        | (_, i) <- fromJust ma
        , (_, j) <- fromJust mc = i * j + acc
      where
        ma = M.lookupLT b as
        mc = M.lookupGT b cs

main :: IO ()
main = do
    n <- readLn :: IO Int
    as <- M.fromAscListWith const . (flip zip [1..]) . sort . fmap readi . B.words <$> B.getLine
    bs <- fmap readi . B.words <$> B.getLine
    cs <- M.fromAscListWith (flip const) . (flip zip [n, n-1 ..]) . sort . fmap readi . B.words <$> B.getLine
    print $ solve as bs cs

-- 入力例3
-- 6
-- 3 14 159 2 6 53
-- 58 9 79 323 84 6
-- 2643 383 2 79 50 288

-- IntMapを表示した結果
-- fromList [(2,1),(3,2),(6,3),(14,4),(53,5),(159,6)]
-- fromList [(2,6),(50,5),(79,4),(288,3),(383,2),(2643,1)]