{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector Int -> Int
solve !n !an = maximum $ zipWith (-) calcSumAs (reverse calcSumBs)
 where
  minHeap =
    S.fromList $ VU.toList $ VU.imap (\(!i) (!a) -> (a, i)) $ VU.take n an
  maxHeap = S.fromList $ VU.toList $ VU.imap (\(!i) (!a) -> (a, i)) $ VU.drop
    (2 * n)
    an
  sumA      = VU.sum (VU.take n an)
  sumB      = VU.sum (VU.drop (2 * n) an)

  calcSumAs = (\(_, _, x) -> x) $ foldl'
    (\(!minh, !sumA, !acc) (!i) ->
      let
        ai    = an VU.! (n + i)
        minh' = S.insert (ai, i) minh
        (sumA', minh'') =
          let Just ((m, _), minh'') = S.minView minh'
          in  (sumA + ai - m, minh'')
      in
        (minh'', sumA', sumA' : acc)
    )
    (minHeap, sumA, [sumA])
    [0 .. n - 1]

  calcSumBs = (\(_, _, x) -> x) $ foldl'
    (\(!maxh, !sumB, !acc) (!i) ->
      let
        ai    = an VU.! (2 * n - i - 1)
        maxh' = S.insert (ai, i) maxh
        (sumB', maxh'') =
          let Just ((m, _), maxh'') = S.maxView maxh'
          in  (sumB + ai - m, maxh'')
      in
        (maxh'', sumB', sumB' : acc)
    )
    (maxHeap, sumB, [sumB])
    [0 .. n - 1]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  an <- VU.unfoldrN (3 * n) readInt <$> B.getLine
  print $ solve n an
