import qualified Data.ByteString.Char8 as C
import Data.Int
import qualified Data.IntSet as S
import Data.List

main = C.interact $ C.pack . show . sol . get

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines

main' = interact $ show . sol . fmap (fmap read . words) . lines

sol ::[[Int]] -> Int64
sol [[n],as] = maximum $ zipWith (-) lsum (reverse rsum) 
  where
  lsum = grab $ foldl' f (sl,kl,xl,[xl]) am
  rsum = grab $ foldr g (sr,kr,xr,[xr]) am
  (al,a0) = splitAt n as
  (am,ar) = splitAt n a0
  sl = S.fromList al
  sr = S.fromList ar
  kl = S.findMin sl
  kr = S.findMax sr
  xl = foldl' nsum (0 :: Int64) al
  xr = foldl' nsum (0 :: Int64) ar

nsum s k = s + fromIntegral k

grab (_,_,_,xs) = xs

f (sl,kl,xl,xs) a = (sl',kl',xl',xs')
  where
  (sl',kl',xl',xs') = if a>kl 
    then (S.insert a (S.delete kl sl), S.findMin sl', xl+fromIntegral (a-kl), xl':xs)
    else (sl,kl,xl,xl:xs)

g a (sr,kr,xr,xs) = (sr',kr',xr',xs')
  where
  (sr',kr',xr',xs') = if a<kr
    then (S.insert a (S.delete kr sr), S.findMax sr', xr+fromIntegral (a-kr), xr':xs)
    else (sr,kr,xr,xr:xs)