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

readInt = fst . fromJust . B.readInt

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

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 q1s q2s)
 where
  diff q1 q2 = sumh q1 - (negate (sumh q2))
  q1s = scanl (\q a -> pop (push a q)) (foldr push Empty as1) as2
  q2s = scanr (\a q -> pop (push a q)) (foldr push Empty (map negate as3)) (map negate as2)

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

sumh Empty = 0
sumh (Node x xs) = x + sum (map sumh xs)