import Data.List
import Data.Maybe
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
 
readInt = fst . fromJust . B.readInt

apply n f x = foldr ($) x (replicate n f)
 
main = do
 n <- readLn
 as <- map readInt . B.words <$> B.getLine
 let (as1,as2) = splitAt n as
 let q1 = M.fromListWith (+) (zip as1 (repeat 1))
 let q2 = M.fromListWith (+) (zip as2 (repeat 1))
 print (n3 n q1 as2 q2)
 
n3 n q1 as2 q2 = maximum (fsearch n q1 as2 q2)
 
fsearch n q1 as q2 = do
 let rh0 = sum (map (uncurry (*)) (M.toList q1))
 let rl0 = sum (map (uncurry (*)) (M.toList q2))
 k <- [0..n]
 let (rh,rl) = transfer (n-k) k (rh0,q1) as (rl0,q2)
 return (rh - rl)
 
transfer n' 0 (rh,_) _ (rl,q2) = let (rl',_) = apply n' delmax (rl,q2) in (rh,rl')
 where
  delmax (m,q) = let (k,_) = M.findMax q in (m-k, M.update (\v -> if v > 1 then Just (pred v) else Nothing) k q)
 
transfer n' k (rh,q1) (a:as) (rl,q2)
 | v1 > 1 = transfer n' (k-1) (rh-k1+a, M.insertWith (+) a 1 (M.adjust pred k1 q1)) as (rl-a,q2')
 | otherwise = transfer n' (k-1) (rh-k1+a, M.insertWith (+) a 1 q1') as (rl-a,q2')
 where
  ((k1,v1),q1') = M.deleteFindMin q1
  q2' = M.update (\v -> if v > 1 then Just (pred v) else Nothing) a q2
