{-# LANGUAGE TupleSections #-}

main :: IO ()
main = do
    _ <- getLine
    xs <- getInts
    ys <- getInts
    print $ solve xs ys

solve :: [Int] -> [Int] -> Int
solve xs ys = getSum . foldMap (Sum . calc) $ pair (choise xs) (choise ys)

choise :: [Int] -> [Pair]
choise [] = []
choise [x] = []
choise (x:xs) = [(x,x') | x' <- xs] ++ choise xs

pair :: [a] -> [a] -> [(a,a)]
pair xs = foldr (\y a -> map (,y) xs ++ a) []

calc :: (Pair,Pair) -> Int
calc (xs,ys) = dist xs * dist ys
    where dist (a,b) = abs (a-b)

type Pair = (Int, Int)

newtype Sum = Sum { getSum :: Int }

instance Monoid Sum where
    mempty = Sum 0
    mappend (Sum x) (Sum y) = Sum $ (x+y) `mod` lim

lim :: Int
lim = 7 + 10^9

getInts :: IO [Int]
getInts = map read . words <$> getLine
