module Main where
import List;
import Data.Array;
import Monad;

solve :: [Int] -> [Int] -> Integer
solve as bs = sum $ zipWith (*) (map (count (listArray (1, maxV) has)) [1..maxV]) hbs
    where
        has = hist [1..maxV] ((sort as))
        hbs = hist [1..maxV] ((sort bs))

count bs step = sum $ map (bs !) [step, 2 * step .. maxV]

hist range as = reverse $ fst $ foldl (\(result, as) x -> (toInteger (length (takeWhile (== x) as)) : result, dropWhile (== x) as)) ([], as) range

maxV = 10000

main = do
    (_:as:_:bs:_) <- (liftM (map (map read) . map words . lines) . readFile) "deposits.in"
    writeFile "deposits.out" $ show $ solve as bs
