{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Ord (comparing)
import qualified Data.ByteString.Char8 as B

puts :: [(Int,Int)] -> [Int] -> Int -> [(Int,Int)]
puts _ [] _ = []
puts [] (a:as) c = (a,c) : puts [] as c
puts bb@((b,n):bs) aa@(a:as) c
    | b > a = puts bs aa (c+n)
    | True = (a,c) : puts bb as c

main = do
    _ <- getLine
    as <- sortBy (flip $ comparing id).unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    bs <- sortBy (flip $ comparing id).unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    cs <- (flip zip) [1,1..] . sortBy (flip $ comparing id).unfoldr (B.readInt.B.dropWhile (==' ')) <$> B.getLine
    --
    print $ sum $ map snd $ puts (puts cs bs 0) as 0
