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 as1 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 as1 q1 ais q2 = do
 let rh0 = sum as1
 k <- [0..n]
 let (rh,rl) = transfer (n-k) k (rh0,q1) ais q2
 return (rh - rl)

transfer n' 0 (rh,_) _ q2 = (rh, sum (map fst (S.elems (apply n' S.deleteMax q2))))
transfer n' k (rh,q1) ((a,i2):ais) q2 = transfer n' (k-1) (rh-vmin+a, S.insert (a,i1) q1') ais q2'
 where
  ((vmin,i1),q1') = S.deleteFindMin q1
  q2' = S.delete (a,i2) q2
