{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.IO
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map

main :: IO ()
main = do
  n <- readLn :: IO Int
  list <- map (fromIntegral . readIntBS) . BS.words <$> BS.getLine :: IO [Int64]
  let
    (as,bs) = splitAt n list
    (cs,ds) = splitAt n (reverse list)

  print $ maximum $ zipWith (\a b -> a - b)
    (evalState (func1 bs (sum as) n) (Set.fromList as)) (reverse $ evalState (func2 ds (sum cs) n) (Set.fromList cs))


  where
    func1 _ s 0 = return [s]
    func1 (x:xs) s n = do
      (m,set) <- Set.deleteFindMin . Set.insert x <$> get
      put set
      (s:) <$> func1 xs (s-m+x) (n-1)

    func2 _ s 0 = return [s]
    func2 (x:xs) s n = do
      (m,set) <- Set.deleteFindMax . Set.insert x <$> get
      put set
      (s:) <$> func2 xs (s-m+x) (n-1)
