import Data.List
import qualified Data.Set as S

apply n f x = foldr ($) x (replicate n f)

main = do
 n <- readLn
 as <- map read . words <$> getLine
 print (n3 n as)
 
n3 n as = maximum (fsearch n q1 (zip as2 [0..]) q2)
 where
  (as1,as2) = splitAt n as
  q1 = S.fromList (zip as1 [0..])
  q2 = S.fromList (zip as2 [0..])

fsearch n q1 ais q2 = do
 k <- [0..n]
 let (rh,rl) = transfer (n-k) k (rh0,q1) ais (rl0,q2)
 return (rh - rl)
  where
    rh0 = sum (map fst (S.elems q1))
    rl0 = sum (map fst (S.elems q2))

transfer n' 0 (rh,_) _ (rl,q2) = let (rl',_) = apply n' delmax (rl,q2) in (rh,rl')
 where
  delmax (m,q) = let ((vmax,_),q') = S.deleteFindMax q in (m-vmax,q')

transfer n' k (rh,q1) ((a,i2):ais) (rl,q2) = transfer n' (k-1) (rh-vmin+a, S.insert (a,i1) q1') ais (rl-a,q2')
 where
  ((vmin,i1),q1') = S.deleteFindMin q1
  q2' = S.delete (a,i2) q2
