import Data.Maybe
import qualified Data.ByteString.Char8 as B

readInt = fst . fromJust . B.readInt

main = do
 n <- readLn
 as <- map readInt . B.words <$> B.getLine
 let (as1,as23) = splitAt n as
 let (as2,as3) = splitAt n as23
 print (n3 n as1 as2 as3)

n3 n as1 as2 as3 = maximum (zipWith diff rq1s rq2s)
 where
  diff (rh,_) (rl,_) = rh - negate rl
  rh0 = sum as1
  rl0 = negate (sum as3)
  q1 = foldr push Empty as1
  q2 = foldr push Empty (map negate as3)
  rq1s = scanl (flip pushpop) (rh0,q1) as2
  rq2s = scanr pushpop (rl0,q2) (map negate as2)

pushpop a (r,q) = (r + a - top q', pop q')
 where q' = push a q

data Heap a = Empty | Node a [Heap a] deriving (Show, Eq)

merge Empty h = h
merge h Empty = h
merge (Node x xs) (Node y ys)
  | x < y     = Node x (Node y ys : xs)
  | otherwise = Node y (Node x xs : ys)

mergeList []       = Empty
mergeList [x]      = x
mergeList (x:y:xs) = merge (merge x y) (mergeList xs)

push x h = merge (Node x []) h

pop (Node _ xs) = mergeList xs

top (Node x _) = x