{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE MultiWayIf #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Char
import qualified Data.Map.Strict as M

fun :: M.Map Int Int -> Int
fun m = sum [ k*l | (k,l) <- M.toList m ]

insert' :: M.Map Int Int -> Int -> Int -> M.Map Int Int
insert' m k l = M.insertWith (+) l 1 $ if m M.! k <= 1 then M.delete k m else M.update (\x -> Just $ x-1) k m

main :: IO ()
main = do
    n <- readLn
    xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    let (as,oo) = splitAt n xs
        (bs,cs) = splitAt n oo
    let solve :: Int -> M.Map Int Int -> M.Map Int Int -> [Int] -> [Int] -> Int
        solve 0 m m' _ _ = fun m - fun m' 
        solve count m m' (x:xs) (y:ys) = 
            let xx = fst $ M.findMin m
                yy = fst $ M.findMax m'
                pp = x - xx
                qq = yy - y
            in if | pp > 0 && qq > 0 && pp >= qq -> solve (count-1) (insert' m xx x) m' xs (y:ys)
                  | pp > 0 && qq > 0 && pp < qq  -> solve (count-1) m (insert' m' yy y) (x:xs) ys
                  | pp > 0                       -> solve (count-1) (insert' m xx x) m' xs (y:ys)
                  | qq > 0                       -> solve (count-1) m (insert' m' yy y) (x:xs) ys
                  | otherwise                    -> solve (count-1) m m' xs (y:ys)
    print $ solve n (M.fromListWith (+) [(a,1) | a <- as]) (M.fromListWith (+) [(c,1) | c <- cs]) bs (reverse bs)